Get post ID’s from one query and exclude from another

While running the loop of the first query, just collect the IDs into an array. Example: // define your first query’s arguments $args1 = array( … your first query args ); $query1 = new WP_Query($args1); while ( $query1->have_posts() ): $query1->the_post(); // this is your loop. Do whatever you want here // add this in the … Read more

wp_query, give first post different formatting

Hope I’m understanding you correctly could you not just do something simple like this $args1 = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 4 ); $loop = new WP_Query($args); while ($loop->have_posts()) : $loop->the_post(); echo ‘<h2><a href=”‘.the_permalink().'”>’.the_title().'</a></h2>’; if ($loop->current_post == 0) { echo the_post_thumbnail(); echo the_excerpt(); } endwhile; wp_reset_postdata();

Custom Field sort not working (WP 3.8.1)

I think your query arguments are missing meta_key, which in this case should be ‘event-date’. You need it outside the meta query for orderby to work. Try this: $today = date(“Ymd”, strtotime(current_time(‘mysql’))); $args = array( “post_type” => “post”, “post_status” => “publish”, “posts_per_page” => -1, “cat” => 13, “meta_query” => array( array( “key” => “event-date”, ‘type’ … Read more

WP_Tax_Query with post_tag not working

I did get the thing working, though I’m not entirely sure how. I made two changes: Removed the “convert array to Tax_Query object” step (which I only put in because using an array wasn’t working before) Added a direct assignment of the array to the $query object (rather than just using the set() method). My … Read more

Date query not inclusive despite parameter being true

If you only want to work with yyyy-mm-dd strings, for example ‘2014-10-10’, you could do something like: ‘before’ => ‘2014-10-10 + 1 day – 1 second’, ‘before’ => ‘2014-10-10 + 86399 seconds’, ‘before’ => ‘tomorrow 2014-10-10 – 1 second’, ‘before’ => ‘2014-10-10 tomorrow – 1 second’, or just append ’23:59:59′ to your yyyy-mm-dd string to … Read more

Query wp_usermeta alongside wp_users

This is not a simple answer, so first you will need to include one more filter to allow you to grab both the make the meta_query interact with the main query via an OR instead of a AND, check my sample of code: add_filter(‘user_search_columns’, ‘q166419_user_search_columns’ , 10, 3); function q166419_user_search_columns($search_columns, $search, $this){ if(!in_array(‘display_name’, $search_columns)){ $search_columns[] … Read more

WP_Query pagination not working in admin area

Milo noted that there is no $wp_query object in wp-admin page, so we can get $paged via: $paged = ( $_GET[‘paged’] ) ? $_GET[‘paged’] : 1; Now that we have $paged, we can code our own pagination. I will demonstrate how in its very simplest form. First let’s get maximum pagination pages: $max_pages = $the_query->max_num_pages; … Read more

Query Set Order By Author

To order by the authors nicename is not nativly supported by the WP_Query. If you order by author, as you have experienced, you order by the ID of the author. So, you would need to actually go into the SQL clauses and manage this by yourself. This is a quick and dirty hack to do … Read more

How get posts from a subcategory of a category by name?

// Getting Parent ID $parent = get_term_by( ‘name’, ‘Session 2015’, ‘category’); // Checking if SubCategory Exist. $term = term_exists(‘Photos’, ‘category’, $parent->term_id); //if Exist Do the query if ($term !== 0 && $term !== null) { $query = new WP_Query( ‘cat=”.$term[“term_id’] ); } References: term_exists get_term_by