Link to date_query results in WordPress

You can use $_GET to get the query string values and then pass it in the $args to create a dynamic WP_Query $after = $_GET[‘after’]; $before = $_GET[‘before’]; and then in the $args if ($after && $before) { $args = array( ‘date_query’ => array( array( ‘after’ => $after, ‘before’ => $before, ‘inclusive’ => true, ), … Read more

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

WP_Query custom field pass the post id

1st query: $exclude_post_top_stories=””; // WP_Query arguments $args = array ( ‘post_status’ => array( ‘publish’ ), ‘posts_per_page’ => ‘-1’, ‘order’ => ‘DESC’, ‘orderby’ => ‘date’, ); // The Query $exclude_query = new WP_Query( $args ); // The Loop if ( $exclude_query->have_posts() ) { while ( $exclude_query->have_posts() ) { $exclude_query->the_post(); // do something $exclude_post_top_stories[] = get_the_id(); } … 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