简体   繁体   中英

In wordpress how to get the values from custom post type based on taxonomy

I need to get the values in my page template from custom post type based on taxonomy.

In my project am having four taxonomy as china,japan, singapore, malaysia

Each taxonomy has separate value

Need to retrive the datas accordingly.

For example:

China:

Name1
address1

Name2
address2

Malaysia:

Name1
address1

Name2
address2

and so on.

Kindly suggest some ideas for that. Thanks.

This will loop through the custom post type of 'country' which are tagged with "china".

// WP_Query Arguments
$args = array (
    'post_type'              => array( 'country' ),
    'tag_id'                 => 'china',
);

// The Query
$query = new WP_Query($args);

// The Loop
while ( have_posts() ) : the_post();

    echo '<h1>'.the_title().'</h1>';
    echo $customField[1];
    echo $customField[2];

endwhile;

// Reset Query
wp_reset_query();

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