Using the same WP_Query for shop and widgets in WooCommerce shop

The reasons your pre_get_posts filter does not work on the widget are the condition !$wp_query->is_main_query() makes the filter handle only the main query and nothing else Your special parameter myattr is “self populating” only on the main query but it is not propagating automatically to other queries. To make it work on the widget, the … Read more

How can I display a query in a page?

You can use the $wpdb object // Print last SQL query string $wpdb->last_query or: <?php if (current_user_can(‘administrator’)){ global $wpdb; echo “<pre>”; print_r($wpdb->queries); echo “</pre>”; }//Lists all the queries executed on your page ?> You might have to set define(‘SAVEQUERIES’, true); in wp-config.php

Counting And Monitoring How Much Queries My Script Used

Actually there happens more than single query behind the scene. They are both for getting some needed data and also for updating or creating or inserting data. Say for post terms wp_insert_post() get those data by query. So, where you’re assuming that it should run 40,000 query it actually run more than that. Please have … Read more

Query String for the WP_QUERY parameters

PHP function http_build_query(); would return different string for this array. It won’t remain readable like an array but, I believe, it will work as parameter to WP_Query. build_query is the WordPress equivalent for the same functionality. Turns out that build_query is a bit different from http_build_query. http_build_query returned date_query%5B0%5D%5Bafter%5D=24+hours+ago and build_query returned date_query%5B0%5D%5Bafter%5D=24 hours ago. … Read more

Querying posts from two different categories while looping inside another loop

You should not be using query_posts() for this or anything else. For secondary loops you should be making new WP_Query instances. Since you can (and should) assign instances to different variables they won’t interfere with each other. So your structure would be roughly like this: $outer_query = new WP_Query(); while( $outer_query->have_posts() ) : the_post; $inner_query … Read more

Generating an HTML table from an array based on dynamic key values

Here is the tested solution- // Your sample array $sample_array = array( 0 => array( ‘meta_key’ => ‘cpf_first_name’, ‘meta_value’ => ‘John’ ), 1 => array( ‘meta_key’ => ‘cpf_first_name’, ‘meta_value’ => ‘James’ ), 2 => array( ‘meta_key’ => ‘cpf_first_name’, ‘meta_value’ => ‘Jane’ ), 3 => array( ‘meta_key’ => ‘cpf_gender’, ‘meta_value’ => ‘Male’ ), 4 => array( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)