Articles of wp query

Why is the first query affecting the second query, even after wp_reset_query() and wp_reset_postdata(), but not on the second page?

I am literally clueless as to why the code does not function properly on the first page, but functions as expected on the second page. The second query should return the latest 3 posts in the pagination loop, yet it also returns posts from the first query. Instead of 3 posts on the homepage, there […]

Get post with multiple meta keys and value

I am trying to fetch a post based on the following meta keys. post_code with 432C location with XYZ Both belong to a CPT. I’m trying to fetch the Post with both these meta_values. I Don’t Want an OR relation, I want a AND relation, I have tried several WP_Query objects and still haven’t found […]

Displaying a specific post in a wp query by post id

I’m simply trying to display a specific post id from my custom post type ‘homepage_video’. I’m sure that this is the correct code but it seems to be returning all of the posts rather than just Post Id 40. <?php query_posts(‘post_id=40&post_type=homepage_video’); while (have_posts()): the_post(); ?> <div id=”video-panel-blue”> <?php get_custom_field(‘home-video-iframe’, TRUE); ?> </div> <?php endwhile; ?> […]

WordPress documentation – WP_Query arguments

I’ve been looking for a list all WP_Query arguments. This looks obvious, but http://codex.wordpress.org/Function_Reference/WP_Query isn’t helpful at all, “post_type” is mentioned only in an example, and arguments like “posts_per_page” aren’t even there.

Different Results with query('s=computer') vs get_posts('s=computer')?

I have two different pieces of code and it’s returning two different results. $search_query = new WP_Query(); $search_posts = $search_query->query(‘s=computer’); echo count($search_posts); vs. $search_posts = get_posts(‘s=computer’); echo count($search_posts); What is the reason for the different values? (The value provided by the first one is correct. It’s the same as the number of posts that I […]

Undefined property: WP_Query::$post

I am working on some rather elaborate comparisons between metadata and having a bit of trouble correctly referring to results from my query. The first query to establish $team_is_home works fine but as soon as I try to capture the ID of the posts where the $team_is_homeit goes a bit haywire and I get warnings […]

Why wont this wp_query exclude certain pages?

I’m using the following wp_query snippet to show all pages on a single page while being able to select individual pages to exclude. // This pulls a list of page ID’s from a theme options multicheck field $pages = of_get_option(‘exclude_pages’ ); // This shows only those ID’s that have been checked $implode_pages = implode(‘, ‘,array_keys($pages, […]

Detect featured image among the attached images

I use the following code to extract the attached images from a post with ID: $args = array( ‘post_type’ => ‘attachment’, ‘post_parent’ => $product_id, ‘post_mime_type’ => ‘image’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘numberposts’ => -1 ); $attachments = get_posts($args); The problem is that the above code return all the attached files. Is there a […]

How to check if a post “does not have term” in conditional statement?

We know that we can check if the particular post has a term by using this code: has_term(‘term’, ‘taxonomy’, $post->ID )) { I was wondering if there is a code to check if a particular post does not have a particular term. Thanks.

How can I get the first 50% of all posts (within a custom post type)?

I’m trying to make a multi column layout. Seen as CSS3 adoption of column layouts is still thin on the ground, I was thinking maybe I could grab the first half of all my posts (and then the second), and add them in their own UL elements. I’m not sure how / if this is […]