Page template query with WP_Query

UPDATE: This is now a decade old answer, meant for a very old version of WordPress. I can see the comments informing me that this might not work for newer WP versions, please do refer to the other answers below if mine is not working for your version of WP. For WP 2.*, this will … Read more

Order by multiple meta key and meta value [closed]

meta_query is an array of meta clauses. For example: $q = new WP_Query( array( ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘state’, ‘value’ => ‘Wisconsin’, ), array( ‘key’ => ‘city’, ‘compare’ => ‘EXISTS’, ), ), ) ); You can use an associative array, with a key for each meta clause: $q = new … Read more

Query multiple custom post types in single loop

Just change the post_type bit to: ‘post_type’ => array(‘testimonial’, ‘other_post_type’, ‘another-post-type’), Assuming that taxonomy is valid across all 3 post types. Otherwise you’ll have to leave that out. Why? You can pass an array to post_type field.

Broken? WP_Query and “attachment” as a post type

These are the query parameters i use…works for me when i loop through the results array( ‘post_parent’ => $post->ID, ‘post_status’ => ‘inherit’, ‘post_type’=> ‘attachment’, ‘post_mime_type’ => ‘image/jpeg,image/gif,image/jpg,image/png’ ); For more detail, please see official documentation for WP_Query’s status parameters

$GLOBALS[‘wp_the_query’] vs global $wp_query

You have missed one, $GLOBALS[‘wp_query’]. For all purposes, $GLOBALS[‘wp_query’] === $wp_query. $GLOBALS[‘wp_query’] is however better for readability and should be used instead of $wp_query, BUT, that remains personal preference Now, in a perfect world where unicorns rule the world, $GLOBALS[‘wp_the_query’] === $GLOBALS[‘wp_query’] === $wp_query. By default, this should be true. If we look at where … Read more

Display all posts in a custom post type, grouped by a custom taxonomy

So, you might consider automating the multiple queries. First, get the list of terms in your custom taxonomy, using get_terms(): <?php $member_group_terms = get_terms( ‘member_group’ ); ?> Then, loop through each one, running a new query each time: <?php foreach ( $member_group_terms as $member_group_term ) { $member_group_query = new WP_Query( array( ‘post_type’ => ‘member’, ‘tax_query’ … Read more

numberposts? showposts? posts_per_page?

In my opinion, deprecating numberposts would not make sense, as numberposts is used to query x amount of posts, whilst posts_per_page is used to denote how many posts per page are being shown during pagination. If you were to deprecate numberposts in favor of simply posts_per_page, then pagination would not exist. ie: “numberposts” => 50, … Read more

Should we trust the post globals?

There is a sad truth: you can never ever be sure that some code will not break your code, and there is nothing you can do to prevent that. Especially in WordPress, where everything is global. That said, yes, global $post is one of the most used global var, so using special care for it … Read more

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş