Query of all pages, including children, ordered by meta key

This is what i ended up doing since i found no other way //Fetch all pages $pages = get_pages( array( ‘post_type’ => ‘page’, ‘meta_key’ => ‘review_date’, //’meta_key’ => ‘reviewed_by_user_id’, ‘sort_column’ => ‘review_date’, ‘sort_order’ => ‘asc’ )); //Fetch metadata for each page $ordered_pages = array(); foreach ($pages as $page) { $metadata = get_metadata(‘post’, $page->ID); $user = … Read more

How to display specific ids of posts using wp_query?

this is a fairly broad question since there are multiple solutions depending on your exact needs. My method might involve: Setup normal ‘Loop’ in each iteration grab the featured image using: wp_get_attachment_image_src( get_post_thumbnail_id( post->ID ), ‘large’ ); build an unordered list of images Use a plugin that works with UL listitems to generated a slideshow … Read more

What is wrong with my WP_Query Arguments?

Use this one- ‘category__not_in’ => array( 93, 94, 95 ), instead of- ‘category_not_in’ => 93, Note: The term is category__not_in, not category_not_in. Use 2 underscores after category. Edit: You are using- ‘offset’ => 1 That forces to show posts from 2nd one (skips the first post). So, it’s showing one post less! If you use … Read more

How to use ‘WP_Query’ or ‘query_posts’ to display content in a descending order

You can store the counts as key and link a value and sort them before display like this : $sort_tab = array(); while (have_posts()) : the_post(); if ( has_post_thumbnail() ) { the_post_thumbnail( array(40,40) ); } $url = get_the_permalink(); $json = file_get_contents( ‘https://graph.facebook.com/fql?q=SELECT%20like_count,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%27’ . $url . ‘%27’ ); $json_data = json_decode($json, false); $sort_tab[$json_data->data[0]->total_count] = $url; endwhile; … Read more

Function to retrieve IDs of posts, cache results, and improve wp_query

What the author of the article posted, as I read it, is suggesting you do is something like this: $cats = array(1,2,3,4); $q = new WP_Query( array( ‘category__not_in’ => $cats ) ); var_dump($q->request); You should see the complex default query in that dump. $ids = array_unique(get_objects_in_term($cats,’category’)); var_dump($ids); Now you have an array of post IDs … Read more

Creating attachments archive in tags and categories

The WP_Query documentation on the codex specifically says: ‘attachment’ – an attachment. Whilst the default WP_Query post_status is ‘publish’, attachments have a default post_status of ‘inherit’. This means no attachments will be returned unless you also explicitly set post_status to ‘inherit’ or ‘any’. I am not sure why it was working before because this is … Read more

Add parameter to first post only

Use the property current_post of a WP_Query object – it’ll be zero for the first post: if ( $wp_query->current_post === 0 ) // First post in main loop if ( $get_videos->current_post === 0 ) // First video in current videos loop

Query using string from custom field as array value

Okay anyone wanting to achieve this, the code works. Just save the values in the custom field without quotes. e.g. red, car <?php $list = get_field( “main_attributes” ); $array = explode(‘,’, $list); $args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘style_atrributes’, ‘value’ => $array, ‘compare’ => ‘IN’ ), array( ‘key’ => … Read more

Overriding $wp_query on a template

You are interfering with the main query/loop, which is bad – there is nothing more to say. You can do a custom loop, see the codex article The Loop to start with, or use the pre_get_posts hook, if you want to do something other then the usual behaviour. If you need to toy with $wp_query, … Read more

Show posts of an advanced search form

If I am reading your question right, you need AND not OR for the meta query relation ‘relation’ => ‘AND’, I don’t see where you’ve set the $product_* values either. You should be using $_GET[‘product_color’] (etc), but you need to sanitize that user supplied data. I would use a “whitelist” technique if it were me: … Read more