Get posts by list of post IDs ordered by those IDs?
You could use post__in as a parameter in your WP_Query, like: $favourite_posts = new WP_Query( array( ‘post__in’ => array( 111, 222, 333 ), ‘orderby’ => ‘ID’ ) );
You could use post__in as a parameter in your WP_Query, like: $favourite_posts = new WP_Query( array( ‘post__in’ => array( 111, 222, 333 ), ‘orderby’ => ‘ID’ ) );
You need to get the post ids from the original main query and exclude them. Then you should remove your offset from your custom query. That should do the trick. Random ordering basically ignores the offset parameter, so you need to explicitely remove the posts from the query to exclude them You can use wp_list_pluck() … Read more
As birgire said date query is an array of arrays May be this solves your problemo. $args = array( ‘post_type’ => ‘surf_reports’, ‘posts_per_page’ => ‘1’, ‘category_name’ => $cat (this is pulled dynamically in my template), ‘date_query’ => array( array( ‘after’ => ’24 hours ago’ ) ) );
One of the easier ways to do this is to just add the filter before your query and remove it after: add_filter( ‘posts_orderby’, ‘filter_function’ ); $something = new WP_Query( $args ); remove_filter( ‘posts_orderby’, ‘filter_function’ ); Then you can just add your function into functions.php as normal: /** * The below function filters something * Added … Read more
put this code in functions.php : function change_numberposts( $query ) { // Only modify the main query if( $query->is_main_query() ){ // Home page if ( $query->is_home() ) { $query->set( ‘posts_per_page’, 6 ); } // Category 21 if ( $query->is_category( 21 ) ) { // parameter for is_category may be Category ID, Category Title, Category Slug … Read more
If you will be pulling a lot of posts (or simply want to reduce the number of queries made), I’d recommend re-writing things a little bit. First, build a filter function to modify the query you are about to make. function filter_query_add_likes( $clauses, WP_Query $wp_query ) { if ( !is_admin() && !$wp_query->is_main_query() ) { global … Read more
All 3 of these could do the same thing, it’s just a matter of how you want to use them. the_title() calls get_the_title() which gets the title by $post->post_title. View the_title() Source on Trac View get_the_title() Source on Trac Personally, I would never use choice 3 as from a readability stand point it’s not the … Read more
You can make use the queried object to return the title of the page used as blogpage You can use the following: (Require PHP 5.4+) $title = get_queried_object()->post_title; var_dump( $title );
You could try this instead: $bc_args = array( ‘post_type’ => ‘data’, ‘data-category’ =>’insurance-rate’, ‘order’ => ‘DESC’, ‘orderby’ => ‘meta_value_num’, ‘meta_query’ => array( array( ‘key’ => ‘interest_rate’, ‘value’ => (int) $i_rate, ‘type’ => ‘numeric’, ‘compare’ => ‘>=’ ), ) ); $sortedPosts = new WP_Query( $bc_args ); where we use the numeric type. You should also consider … Read more
Can you try this? $paged = (get_query_var(‘page’)) ? get_query_var(‘page’) : 1;