I'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?
As so: $args = array( 'post_type' => 'post', 'posts_per_page' => -1, 'order' => $sort_by, 'orderby' => 'title', 'post_status' => 'publish', 'tag' => $tags, 'ignore_sticky_posts' => 1, ); This will make Query get all posts in your table.
$query = new WP_Query(array( 'post_type' => 'custom', 'post_status' => 'publish' )); while ($query->have_posts()) { $query->the_post(); $post_id = get_the_ID(); echo $post_id; echo "<br>"; } wp_reset_query();
Now, if you want to display all your posts from a specific category on a separate page, WordPress already takes care of this for you. To find the category page, you simply need to go to Posts » Categories » View page and click on the 'View' link below a category.
To display your custom post types on the same category page as your default posts, you need to add this code into your theme's functions. php or a site-specific plugin. $post_type = array ( 'nav_menu_item' , 'post' , 'movies' ); // don't forget nav_menu_item to allow menus to work!
You can use 'post_type' => 'any'
for fetching from all post types. See this documentation. http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters
Note: It is highly recommended to use WP_Query
rather than query_posts
. https://wordpress.stackexchange.com/a/1755/27998
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With