Show posts from particular category first then remaining wpQuery - php

i want to show the posts from particular category and after that all remaining posts from other remaining category.
this is my query. what changes to done in $args array for achieving my goal.
note that i can only use one loop.
this is my query.
$args = array(
'post_type' => 'event',
'meta_key' => '_event_end_date',
'meta_compare' => '>',
'meta_value' => $today,
'order' => 'DESC',
'orderby' =>'category',
'paged' =>$paged1,
);

Related

WordPress sort wp_query multiple meta_values

I would like to sort my post and tried nearly everything to make it work.. but no luck :-(
In my loop is a custom post type called deal and expired deal (meta_value through ACF) posts. I want to show the normal posts first and then the expired posts.
This is my code so far:
$args = array(
'posts_per_page' => -1,
'post_type' => 'deal',
'orderby' => 'date',
'order' => 'DESC',
'post__not_in' => array($not_in),
);
Any ideas how I can put the "expired" posts behind the normal posts?
What you want to do is set orderby to meta_value and meta_key to your custom field.
$args = array(
'posts_per_page' => -1,
'post_type' => 'deal',
'meta_key' => 'YOURCUSTOMFIELDHERE',
'orderby' => 'meta_value',
'order' => 'DESC',
'post__not_in' => array($not_in),
);
If the DESC order is the wrong direction you can switch it to ASC.

Order posts by highest rated in Wordpress

I'm creating a site with overviews of posts which should possibly be ordered by their rating. The rating is set up in a way that people can comment on a post and submit a rating with that comment of they want. I want to create a filter that gets all the posts and shows the highest rated posts first.
The way I get the comments for a single post:
get_comments( array('post_id' => $post->ID) );
The way I get the rating from that post:
get_comment_meta($comment->comment_ID, 'cijfer', true );
Now keep in mind that not every comment will have an actual rating attached to it. How can I modify this bit of code that gets my posts to order them by rating High -> Low.
$order = array (
'order' => 'ASC',
'cat' => $cat,
'post_type'=> 'adressen',
'paged' => $paged,
);
From the docs https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
'orderby' with 'meta_value' and custom post type
Display posts of type 'my_custom_post_type', ordered by 'age', and filtered to show only ages 3 and 4 (using meta_query).
$args = array(
'post_type' => 'my_custom_post_type',
'meta_key' => 'age',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'age',
'value' => array( 3, 4 ),
'compare' => 'IN',
),
),
);
$query = new WP_Query( $args );
Hope this helps

WordPress: switch meta_query orderby in the frontoffice

Was looking for a while for a solution, but couldn't find one. So my question is, I have this code that sets posts order by default its DATE:
$args = array(
'post_type'=>'paibcresume',
'posts_per_page' => 10,
'paged' => $paged,
'meta_query' => array(),
'tax_query' => array(),
'orderby' => 'date',
'meta_key' => '',
'order' => 'DESC'
);
I need some kind of a switch on the website, so user can pick how to order posts, for example it could be date to order by date, or modified to order by date of modification, or it could be a custom meta_key. How could I do that?
Check below url
http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
$query = new WP_Query( array ( 'post_type' => 'product', 'orderby' => 'meta_value_num', 'meta_key' => 'price' ) );

determine posts per page in second loop wpQuery

I have multiple loops using wp_query() in WordPress.
I want to show the posts from first loop first (post per page=10),
and if there are no posts from first loop show, then show the second loop.
For example, if I only have 8 posts from first loop, the second loop should show 2 posts.
The loop is working properly, but I can't solve the post per page issue. How can I do this? I also need pagination for the remaining posts.
$args = array(
'post_type' => 'event',
'event-categories' => 'featured',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
$loop = new WP_Query( $args );
$args1 = array(
'post_type' => 'event',
'event-categories' => 'abc'
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
$loop1 = new WP_Query( $args1);

Wordpress loop for multiple custom post types

Looking for a way to loop through multiple custom post types and get the 4 most recent posts.
I have the below but doesn't quite work as if you 2 posts of the same post type, it'll show the most recent rather than showing most recent of ALL custom posts.
$args = array('post_type' => array('cs_trainee', 'cs_graduates', 'cs_pros', 'sd_trainee', 'sd_graduates'), 'posts_per_page' => 4, 'orderby' => 'menu_order', 'order' => 'ASC');
$careers = new WP_Query( $args );
Thanks
Just change the query_posts parameters a bit....
query_posts( array(
'post_type' => array( 'post', 'report', 'opinion', bookmark' ),
'cat' => 3,
'orderby' => 'date',
'order' => 'DESC',
'showposts' => 5 )
);
That should take care of it for you.

Categories