get query’s query string
Take a look at global $query_string;. Or var_dump( $GLOBALS[‘wp_query’] );.
Take a look at global $query_string;. Or var_dump( $GLOBALS[‘wp_query’] );.
Aha, despite there being a postmeta field of post_name->’slug’, the correct syntax (which mirrors that of WP_Query, is $args = array( ‘name’ => $postSlug, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’ ); $slugPosts = get_posts($args); Where ‘name’ is the key in the query (for posts, ‘postname’ for page). Doesn’t make much sense but might as well … Read more
Just inspect the current post content for ‘<!–nextpage–>’: function wpse_check_multi_page() { $num_pages = substr_count( $GLOBALS[‘post’]->post_content, ‘<!–nextpage–>’ ) + 1; $current_page = get_query_var( ‘page’ ); return array ( $num_pages, $current_page ); } On page 2 of 3 that returns: Array ( [0] => 3 [1] => 2 ) On an unpaged post it returns: Array ( … Read more
Sorting your posts by relevance This will need to add an extra propperty to each post. Than sort the object by this new prperty. The trick is to sort the posts directly in the query object. function get_posts(){ // get the posts but do NOT order them $query_posts = new WP_Query( array( ‘numberposts’ => 5 … Read more
The WP_Query page on the Codex has a section on Order & Orderby Parameters. If you want to order the query by a custom field you should add ‘orderby’ => ‘meta_value’ AND you must also specify the custom field (called your_date_field in the above example) using the meta_key key in the query. $timeline_query = new … Read more
The is_home() conditional returns true when the currently displayed page is the blog posts index. If you want to target the site front page specifically instead, you need to use is_front_page(): function wpse83754_filter_pre_get_posts( $query ) { if ( $query->is_main_query() && is_front_page() ) { $query->set( ‘post_type’, array( ‘home_portfolio’ ) ); } } add_action( ‘pre_get_posts’, ‘wpse83754_filter_pre_get_posts’ ); … Read more
This was done to restrict the effect of those filters to this one query between both calls. There are probably other instances of WP_Query during page load, and you don’t want to change their results. Imagine what happens when you do not remove the filter: All later new WP_Query(); calls would be restricted to a … Read more
I did something similar, the technique you need to use is called a meta query. Here is the query I wrote to get posts based on a date value stored as a custom field meta value. query_posts( array( ‘post_type’=>’post’, ‘order’=>’ASC’, ‘orderby’=>’meta_value_num’, ‘meta_key’=>’date_event’, ‘posts_per_page’=> -1, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘date_event’, ‘value’ … Read more
WP_Query is not capable of that kind of logic without a lot of help. There are a few things you can do though: Just run two distinct queries, one for each post type. This is simple and quick but your posts aren’t “mixed” together. I don’t know if that is what you want. You’d then … Read more
Try adding a condition to your filtering function that checks your post type against get_post_type. if ( ‘book’ == get_post_type() ) If you wish to apply this filter to pages as well, try is_singular() and include your custom post type(s) as an argument. is_singular(‘book’); This will return true if any of the following conditions are … Read more