I want to order posts first by date and second by views
New update :
$trending_songs = new WP_Query(array(
'post_type' => 'songs',
'showposts' => $songs_count,
'cat' => 'songs_cat-689',
'orderby' => 'meta_value_num',
'meta_query' => array(
array(
'orderby' => 'date',
'order' => 'DESC',
),array(
'key' => 'views',
'order' => 'DESC',
)
),
));
the date is not working in the post (they just order by views)
You can use something like below code (this is just for sample you need to change according to your requirement)
<?php
$args = array(
'post_type' => 'words',
'meta_query' => array(
array(
'key' => 'word_count',
'orderby' => 'date',
'order' => DESC
,
),
array(
'key' => 'title',
'orderby' => 'date',
'order' => DESC
),
array(
'key' => 'word_type',
'orderby' => 'date',
'order' => DESC
),
),
);
$query = new WP_Query( $args );
?>
Related
I have a list of events and I'd like to do 2 things :
order posts according to starting date
don't include passed events in the query
I did some research and builded a query but it doesn't work.
'''
$current_date = date_i18n('d.m.y');
$the_query = new WP_Query( array(
'post_type' => 'spectacles',
'meta_query' => array(
array(
'key' => 'header_spec_period_start',
'type' => 'DATE'
),
array(
'key' => 'header_spec_period_end',
'value' => '$current_date',
'compare' => '>',
'type' => 'DATE'
),
),
'order' => 'ASC' ) );
?>
'''
All the events are showing, I can't get the passed events filtered.
$date_now = date('Ymd');
$args = array(
'post_type' => 'spectacles',
'post_status' => 'publish',
'meta_key' => 'header_spec_period_start',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_query' => array(
array(
'key' => 'header_spec_period_start',
'compare' => '>',
'value' => $date_now,
),
),
);
$the_query = new WP_Query( $args );
You can try this ...
I have a WordPress custom loop which looks like this:
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'meta_key' => 'publication_type',
'meta_value' => 'uma',
);
This shows 6 posts with publication_type equal to "uma". The publication_type is a field created with Advanced Custom Fields.
I've also created the field publication_year which contains 2019, 2018, 2017,...
How is it possible to order all my posts descending?
The following example doesn't do a thing:
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'order_by' => 'publication_year',
'order' => 'DESC'
'meta_key' => 'publication_type',
'meta_value' => 'uma',
);
$args = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'publication_type',
'value' => 'uma',
),
),
'meta_key' => 'publication_year',
'orderby' => 'meta_value_num',
'order' => 'ASC',
));
I am using wp_query to get post but i want it's order by date saved in my post meta
I try it using meta_key and order_by but it's not working
$args = array(
'post_type' => 'obituary',
'posts_per_page' => 10,
'paged' => $paged,
'meta_key' => 'user_date_of_death',
'orderby' => 'meta_value',
'order' => 'ASC',
);
$the_query = new WP_Query( $args );
and date saved format in post meta is 06/28/2016
Use below argument in the post query.
$today_date = date('m/d/Y', strtotime('+2 hours'));
$args = array( 'post_type' => 'obituary',
'order' => 'ASC',
'meta_key' => 'user_date_of_death',
'orderby' => 'meta_value',
'meta_query' => array(
array(
'key' => 'user_date_of_death',
'value' => $today_date ,
'compare' => '>=',
'type' => 'DATE'
)
)
);
I want to query the posts that have been set as "featured" and order them by their "priority" field at the same time.
featured field is a true/false type and priority field is a number, and they are created by ACF plugin.
here is my code, but it's not working...
$args = array(
'post_type' => 'tour',
'posts_per_page' => 8,
'orderby' => 'meta_value_num date',
'meta_key' => 'priority',
'meta_query' => array(
array(
'key' => 'featured_tour',
'value' => true,
'compare' => '=',
),
),
);
$query = new WP_Query( $args );
try this :
$args = array(
'post_type' => 'tour',
'posts_per_page' => 8,
'orderby' => 'meta_value_num',
'order'=>'DESC',
'meta_key' => 'priority',
'meta_query' => array(
relation=>'AND',
array(
'key' => 'featured_tour',
'value' => true,
'compare' => '=',
),
array(
'key' => 'priority',
'value' => array(1,6), //YOUR VALUES
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
),
);
$query = new WP_Query( $args );
I have a post with three meta-fields.
add_post_meta($my_post, 'times', $times);
And i would like to query this category and sort the posts by the meta field value of one of them.
The args i use right now are:
$args=array(
'post_type' => 'post',
'category_name' => 'players',
'order' => 'DESC',
'orderby' => 'meta_value_num',
'meta_key' => 'times',
'meta_query' => array(
array(
'key' => 'times',
'value' => 0,
'compare' => '>=',
),
'posts_per_page'=> '8'
)
);
Where times is the name of the metafield.The above code isn't returning anything.
You have 'posts_per_page'=> '8' inside your meta_query argument.
Change your code into the following:
$args=array(
'post_type' => 'post',
'category_name' => 'players',
'order' => 'DESC',
'orderby' => 'meta_value_num',
'meta_key' => 'times',
'meta_query' => array(
array(
'key' => 'times',
'value' => 0,
'compare' => '>=',
)
),
'posts_per_page'=> '8'
);