- This topic is empty.
- AuthorPosts
-
May 31, 2015 at 6:58 am #9961
pshoeg
ParticipantI’m using
query_posts
to get a list of most popular posts. I’m using several custom post types, and instead of including all of them in the query, I would like a query that just gets all of them, also if I create more.This is what I have:
query_posts(array( 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'post_type' => array('posttype1', 'postype2', 'posttype3') ) );
If I don’t include the
post_type
, it only gets the standard post type,post
. Does anyone have an idea?May 31, 2015 at 10:08 am #9964nilambar-sharma
ParticipantYou can use
'post_type' => 'any'
for fetching from all post types. See this documentation. http://codex.wordpress.org/Class_Reference/WP_Query#Type_ParametersNote: It is highly recommended to use
WP_Query
rather thanquery_posts
. https://wordpress.stackexchange.com/a/1755/27998June 22, 2020 at 10:24 am #9963dee_ell
Participant'post_type' => 'any',
This gets all posts except revisions. https://developer.wordpress.org/reference/classes/wp_query/#post-type-parameters
So your query would be:
query_posts(array( 'post_type' => 'any', 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'post_type' => array('posttype1', 'postype2', 'posttype3') ) );
August 16, 2020 at 1:31 am #9962jules-colle
ParticipantIf you want to use
get_posts()
, the only work around is to use'post_type' => get_post_types()
Example that returns ALL posts of ANY post type:
$posts = get_posts([ 'post_type' => get_post_types(), 'post_status' => 'publish', 'numberposts' => -1, ]);
- AuthorPosts
- You must be logged in to reply to this topic.