简体   繁体   中英

WP Query to custom post type or category

i've searching with no luck how to generate a custom wp_query that retrieve an specific category and post type = 'post' or just custom post type = 'bc'.

The idea is to "merge" in a page all posts with custom type 'bc' or category 'my-cat'.

I did a custom query without wp_query, just a custom made and ran it but seems to be very memory expensive and apparently is breaking my db, thats why i would like to try it as arguments of a new WP_Query().

Any idea please? thank you.

See this section in the wordpress codex. http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

$args = array(
    'post_type' => 'bc', // or 'post' if you don't want your custom post type
    'category_name' => 'my-cat'
);

$query = new WP_Query($args);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM