WP Group posts by year(desc) > month(desc) > date(asc)

$last_month = null; $args = array( ‘post_type’ => ‘post’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘post_status’ => ‘publish’ ); $the_query = new WP_Query($args); while ( $the_query->have_posts() ) : $the_query->the_post(); $the_month = get_the_time( ‘Ym’ ); // e.g. 201611 if ( $last_month !== $the_month ) { if ( $last_month !== null ) { // Close previously opened … Read more

Query all posts if multiple meta key don’t exist

global $wpdb; $excludeposts = “SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_status=”publish” AND meta_key NOT LIKE %aa_% ORDER BY post_date DESC “; $main_query = new WP_Query( array( ‘post__not_in’ => $excludeposts, ‘paged’ => $paged ) ); while ($main_query->have_posts()) : $main_query->the_post(); //Stuff… endwhile; //hope this helps

WP_Query : Search and Filter Using custom field AND/OR custom taxonomy

Maby this example can help: <?php global $wp_query; // get the global object $thesearch = get_search_query(); // get the string searched // merge them with one or several meta_queries to meet your demand $args = array_merge( $wp_query->query, array( ‘meta_query’ => array( array( ‘key’ => ‘field_to_seach’, ‘value’ => $thesearch, ‘compare’ => ‘IN’ ) ) )); query_posts( … Read more

slow query – Search for Media Gallery

Time: 2016-12-30T16:28:07.386551Z User@Host: info_234[info_234] @ localhost [] Id: 6390731 Query_time: 4.187182 Lock_time: 1.953823 Rows_sent: 40 Rows_examined: 644073 SET timestamp=1483115287; SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_postmeta AS sq1 ON ( wp_posts.ID = sq1.post_id AND sq1.meta_key = ‘_wp_attached_file’ ) WHERE 1=1 AND (((wp_posts.post_title LIKE ‘%электр%’) OR (wp_posts.post_excerpt LIKE ‘%электр%’) OR (wp_posts.post_content LIKE ‘%электр%’) OR ( … Read more

use of 10 new WP_Query : loading too slow (with url) [closed]

Why don’t you create a category-bio.php template that uses the normal loop? The WordPress query will already be built and you won’t have to have to create a new query just to do an operation that is already happening already. You should really look at Wordress’ Template Hierarchy http://codex.wordpress.org/images/1/18/Template_Hierarchy.png You can target specific categories with … Read more