简体   繁体   中英

WordPress Custom Post type

I create WordPress custom post type and show post by taxonomy here is code

$args = array('post_type' => 'financial_news', 'tax_query' => array( array ( 'taxonomy' => 'news_category', 'field' => 'slug', 'terms' => 'pakistan' ) ), 'posts_per_page' => '7');
$query = new WP_Query($args);
    if ( $query->have_posts()) :
        $count = 0;
        while( $query->have_posts()) : $query->the_post();

When code is run it show all posts, but I want to only show those post that are in Pakistan how can I do?

you could use Simple Taxonomy Query as depicted on http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

so it should look something like this

$args = array('post_type' => 'financial_news', 'news_category' => 'pakistan', 'posts_per_page' => '7');

use http://admin-builder.com to create custom post types and meta boxes and fields of all kind.. it's easier than coding. And it all just works

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