If you want to add custom post type with a custom taxonomy in WordPress? use WP_Query to fetch posts what you need. Read documentation for it. In your case the query could be like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $the_query = new WP_Query( array( 'post_type' => 'Adverts', 'tax_query' => array( array ( 'taxonomy' => 'advert_tag', 'field' => 'slug', 'terms' => 'politics', ) ), ) ); while ( $the_query->have_posts() ) : $the_query->the_post(); // Show Posts ... endwhile; /* Restore original Post Data * NB: Because we are using new WP_Query we aren't stomping on the * original $wp_query and it does not need to be reset. */ wp_reset_postdata(); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.