Posts by Ricardo Moraleida • 4,005 points
175 posts
-
1
votes2
answers51
viewsA: How to publish mass posts via database
It seems that you have solved with SQL, all right, but the record remains: you can use the WP-CLI to solve this via command line, or by writing a script in php, instead of doing all this maneuver:…
-
0
votes1
answer144
viewsA: Db external wordpress
It is possible to log in by reading data from an external database? Yes. You can create authentication streams that intercept login and check information against any other system before…
-
1
votes1
answer131
viewsA: Working with two different "remotes" with git
Git and versioning systems in general should not store sensitive data such as passwords and credentials, even in private repositories. This is precisely because once in history this kind of problem…
-
0
votes1
answer20
viewsA: I need to use only wp_posts from another db Wordpress
Unless you have a great justification to load the comic book directly, use the REST API wordpress native: For example: GET https://site01.teste/wp-json/wp/v2/posts or $posts = wp_remote_get(…
-
3
votes1
answer173
viewsQ: How to Refactor Legacy JS to Implement Unit Tests?
I have a Wordpress site with many JS files that have not been structured to be tested - they have not been written as modules that can be imported nor is there a app.js that loads them all as a…
-
1
votes1
answer45
viewsA: Wordpress shortcode to insert layouts
Use get_template_part() to give the include using the Wordpress API. It is simpler, fails silently (no error if the file does not exist) and still allows access to templates manipulation filters:…
-
0
votes1
answer42
viewsA: Directory of scripts not recognized
Assuming that the folder assets exists within its theme, its path is probably wp-content/themes/nomedotema/assets/. As it is, PHP searches in /assets and finds nothing. That said, you are not using…
-
0
votes1
answer74
viewsA: Import featured images without having to download them. - WORDPRESS
If you have SSH access to the server, you can use the WP CLI to export only what you want from the bank: $ wp db export --tables=wp_posts,wp_postmeta posts.sql This command exports only tables…
-
0
votes1
answer154
viewsA: Related Posts by Child Categories
I understood two different things of the question, so follow two answers: If what you need is to have a specific category that when you are present the related posts will only be hers, use this:…
-
1
votes2
answers57
viewsA: Query in two different tables in Wordpress
You do not need to make a query via SQL directly for this. You can use get_users to get a list, and get_user_by() if you want a specific user. Both return objects WP_User that has all the…
-
1
votes1
answer62
viewsA: Do an if for another line
If you’re not sending files, you don’t need to process the superglobal validation $_FILES. Check if it’s empty first with empty(): if(filter_input(INPUT_POST, "btnSubmit")){ if(!empty($_FILES)) { //…
-
0
votes1
answer212
viewsQ: jsonb: how to fetch the value of the same key of all objects in an array?
I have a type column jsonb that stores objects in an array. I can get the key template of all index objects 0 thus: psql=# select data->'components'->0->'template' as template from page;…
-
1
votes1
answer23
viewsA: Show Thumbnails of a particular wordpress page
The template is saved as a meta_value from the page, you can search like this: $args = array( 'post_type' => 'page', 'meta_query' => array( array( 'key' => '_wp_page_template', 'value'…
-
2
votes3
answers226
viewsA: Doubt in git usage
In my experience, the first thing you need to define before choosing a workflow for the git is what your release cycle. The best model for your case depends on a main variable: The code that is in…
gitanswered Ricardo Moraleida 4,005 -
3
votes3
answers2526
viewsA: Download website with php
You don’t need to download a "any" website to learn these concepts. There are several systems ready, available for free, that already have this functionality incorporated and that you can study. Two…
-
1
votes2
answers940
viewsA: How do I display the content of my wordpress pages?
You should use the Template Tags, who seek the specific information you want, for example, the_content or the_title to bring the text and the title. Here is an example of the theme Twentyfifteen:…
-
0
votes1
answer21
viewsA: Link authors at the end of each wordpress post
The functions the_author_posts_link() and get_the_author_posts_link() build the complete link, already with HTML tags, for example: <p>Confira outros posts de <?php the_author_posts_link();…
wordpressanswered Ricardo Moraleida 4,005 -
1
votes1
answer216
viewsA: Get post from a single category with have_posts() Wordpress
Since version 4.7 of Wordpress no longer need to load Wordpress this way to search for content, just use the native REST API: <?php $curl = curl_init(); curl_setopt_array($curl, array(…
-
0
votes1
answer3801
viewsA: Error Message: Can’t use Function Return value in write context in
You must be using an older version of PHP in which empty only accepts variables, not function returns. change: if(!empty(get_option('config_infoweb'))){ for $config_infoweb =…
-
0
votes1
answer720
viewsA: How to insert ads every x text paragraphs
After editing the question: It seems to me that the problem is that you are inserting the script adsbygoogle.js when in fact you should insert only once, as well as the (adsbygoogle =…
-
1
votes1
answer197
viewsA: Sort Both by Publication Date and by Update
If a post has been published and has not been modified, the update date is the same as the publication date, then you can simply use the update date: $posts = get_posts(array( 'numberposts' => 4,…
-
2
votes1
answer625
viewsA: Specific css file for each wordpress page
The correct way to add CSS to a Wordpress site is by using wp_enqueue_style. You can do it in your functions.php: add_action( 'wp_enqueue_scripts', 'meu_css' ); function meu_css() {…
-
0
votes2
answers68
viewsA: PHP - How to add content to the log?
You can use set_error_handler to generate customized error messages for all levels or only those that interest you. This function is called before the standard PHP error handling. Example of the…
phpanswered Ricardo Moraleida 4,005 -
1
votes2
answers489
viewsA: Delete post through meta_value Wordpress
This question is old but I will document here a way of doing that is independent of creating categories as suggested in the other answer. The Post Expirator plugin saves expiration dates on…
wordpressanswered Ricardo Moraleida 4,005 -
3
votes1
answer760
viewsA: Bash alias with parameters
You have some options to pass parameters. My favorite is to turn the alias into a function and treat the parameters individually: executarArquivo() { python arquivo.py "$1" "$2" "$3"; } In this…
-
4
votes4
answers951
viewsA: Foreach in PHP reverse process
Initialize total item count $i = count( $listagem ); foreach($listagem as $valor){ echo $i; // 100, 99, 98, etc $i--; }
phpanswered Ricardo Moraleida 4,005 -
1
votes1
answer25
viewsA: Conditional in has_post_thumbnail
Is missing close the if where you check if the thumbnail exists: <?php if(has_post_thumbnail($post->ID)) : ?> <div class="entry-image"> <img src="<?php…
-
12
votes2
answers10833
viewsA: What are CRON JOBS and how to use them with PHP
Cron is a task scheduler present on Unix systems. It only does this: schedules tasks to be performed at regular intervals. In answer to your question they gave you this code: 59 23 * * * php -f…
-
1
votes1
answer396
viewsA: Add custom image type Metabox in Wordpress
The process to create an uploading field using native Wordpress modes is a little different, just load the right libraries and create a text input, or Hidden, to save the value. Something like this,…
-
1
votes1
answer660
viewsA: javascript, mouse position in an element
If the mouse may not have moved, you can use the event mouseenter to pick up the initial coordinates, then continue updating the coordinates with onmousemove as you are already doing. var x = null;…
-
2
votes1
answer85
viewsA: How to return array indices in method
You are creating an array composed of other arrays here: $tokens[] = [ 'user_token' => $token['user_token'], 'user_token2' => $token['user_token2'] ]; So to access the internal arrays you…
-
1
votes3
answers1201
viewsA: Accented characters are considered as two characters
You are correct, strlen() returns the number of bytes. To return the number of characters, use mb_strlen() or iconv_strlen(): $t = "à"; print strlen($t); // 2 print mb_strlen($t); // 1 print…
phpanswered Ricardo Moraleida 4,005 -
1
votes1
answer173
viewsA: Property bar and database for Phpstorm
Phpstorm has a database tool that you can access on View > Windows Tool > Database As for the Property Bar there is nothing similar because the purpose of Phpstorm is not to be a website…
phpstormanswered Ricardo Moraleida 4,005 -
2
votes2
answers214
viewsA: jquery time Picker, create function for "min time"
For documentation you can use the method change to modify another input when the current one is modified, using the option. Take an example: $(function() { $('.timepicker-saida').timepicker({…
-
1
votes1
answer57
viewsA: Show terms of a taxonomy randomly
Apparently apply_filters is always returning an array there, so just reorder the array using shuffle to get jumbled: $categorias = apply_filters('taxonomy-images-get-terms', '', array( 'taxonomy'…
-
3
votes2
answers851
viewsA: Database connection - PDO
In the official documentation: PDO::MYSQL_ATTR_INIT_COMMAND (integer) Command to run when connecting to Mysql server. It will be executed again when reconnecting. Note that this constant can only be…
-
1
votes1
answer19
viewsA: How to do first system installation check on a server
The fundamental step that Wordpress uses to understand whether it is already installed or not is to search for the file wp-config.php, this happens in the archive wp-load.php, around line 34. If it…
wordpressanswered Ricardo Moraleida 4,005 -
1
votes1
answer23
viewsA: Filter texts without wordpress formatting
Use wp_kses to filter your content only with tags allowed: // remove todas as tags exceto as h2 echo wp_kses( $post->post_content, array( 'h2' => array() ); The link has the correct format of…
-
2
votes3
answers274
viewsA: Add javascript to Wordpress plugin
I see two things that can potentially give problem there, but nothing guarantees that they are. The first is to use dirname(__FILE__) instead of get_template_directory_uri(): function…
-
2
votes1
answer119
viewsA: View wordpress posts with SQL
I know I’ll have to create a file to connect to the database data and include in index.php and write a sentence in SQL You don’t need any of this. As of version 4.7 you can use the REST Wordpress…
-
2
votes2
answers164
viewsA: Filter Loop Wordpress
It’s not very clear what you want. The loop is just an iteration over a set of posts coming from a query: if( have_posts() ) { while( have_posts() ) { the_post(); } } In the case of the "original"…
wordpressanswered Ricardo Moraleida 4,005 -
0
votes1
answer95
viewsA: How to allow access to the page FORM ONLY
Wordpress has a native solution that can help you: nonces. In fact nonces are a security feature to prevent attacks CSRF, but I think they might be a simple solution for you. On your form page,…
-
1
votes1
answer297
viewsA: Add custom wordpress taxonomy field
You will set the fields outside the function of registering taxonomy, using the actions {taxonomy}_edit_form_fields and/or {taxonomy}_add_form_fields add_action( "categoriaServico_edit_form_fields",…
-
0
votes1
answer23
viewsA: Maintaining the URL / Wordpress
Solution possible, not tested: in his wp-config.php, place: $dominios = array( 'dominio1.com.br', 'dominio2.com.br' ); if ( in_array( $_SERVER['HTTP_HOST'], $dominios, true ) { define('WP_HOME',…
-
1
votes1
answer118
viewsA: wordpress add_rewrite_rule with custom field
This association does not exist in the standard arguments, but you can create so: add_action('init', 'custom_rewrite_basic'); function custom_rewrite_basic() { // Crie uma rewrite tag junto à…
-
0
votes2
answers177
viewsA: Category Wordpress Problems
The problem is here: $terms = get_the_terms( get_the_ID(), 'category'); if( !empty($terms) ) : $term = array_pop($terms); $slug = $term->slug; endif; get_the_terms() brings a list of the…
-
0
votes1
answer691
viewsA: List current category/subcategory subcategories and posts
You are rewriting the query within section, so it will always show the posts of the first category. This line is unnecessary and is breaking the template, can delete entire: <?php…
-
0
votes2
answers395
viewsA: How to make CSS hide a PHP routine
it continues assigning the number 3 to the variable when the browser is resized What you want is impossible. Assigning the value to the variable happens before anything is displayed on the screen -…
-
0
votes1
answer18
viewsA: Plugin does not create page
Try to pass post_date_gmt together. Strange things happen without this parameter: $time = time(); $post = array( 'comment_status' => 'open', 'ping_status' => 'closed' , 'post_date' =>…
-
0
votes2
answers303
viewsA: Error number_format
Commas as a thousand separator (American format) confuse the number_format. Remove and leave only the point as decimal separator: $valor = '1,250.00'; $valor_real = number_format($valor,2, ',',…
phpanswered Ricardo Moraleida 4,005