Learning to display taxonomy posts?

Here is the situation, I have a special tax called "Skill". I want to show messages with only a set of skills, like Japanese from English.

I am trying to learn how to use pre_get_posts hook to modify my get_posts request. Here is my example, however I am landing with an error:

Note: Undefined variable: postdata p>

Here is what I tried based on research:

add_filter( 'pre_get_posts', 'wpshout_fundraiser_recent_posts' ); function wpshout_fundraiser_recent_posts( $query ) { // Fetch only posts tagged with "Japanese from English" $taxquery = array( array( 'taxonomy' => 'Japanese from English', 'field' => 'skill', 'terms' => array( 'skill' ), ) ); $query->set( 'tax_query', $taxquery ); 

I am sure that something is wrong with the above request, which I do not quite understand. Any help and please explain why, if possible, each field of the array.

+7
php wordpress
source share
4 answers

Try this code below that should work,

 add_filter( 'pre_get_posts', 'wpshout_fundraiser_recent_posts' ); function wpshout_fundraiser_recent_posts( $query ) { $posts_array = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'Your Post Type Name', 'tax_query' => array( array( 'taxonomy' => 'Japanese from English', 'field' => 'skill', 'terms' => array( 'skill' ), ) ) ) ); return $posts_array; } 
+5
source share

Here you can check:

 $args = array( 'posts_per_page' => 5, 'post_type' => 'Post Type Name', 'tax_query' => array( array( 'taxonomy' => 'category_taxonomy', 'field' => 'slug', 'terms' => "Category Name" ))); $query = query_posts( $args ); while (have_posts()) : the_post(); the_content(); endwhile; 

view more

0
source share
 $posts_array = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'post_type_name', 'tax_query' => array( array( 'taxonomy' => 'taxonomy-name', 'field' => 'term_id', 'terms' => $cat->term_id, ) ) ) ); 
0
source share

You can try this code below:

  $custom_args=array( 'post_type' => "Your Post Type Name", 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> -1, 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'number' => '', 'tax_query' => array( array( 'taxonomy' => 'Your taxonomy slug', 'field' => 'slug', 'terms' =>"'Your Category Name" ) ), 'orderby' => 'id', 'order' => 'ASC' ); $custom_my_query = null; $custom_my_query = new WP_Query($custom_args); $custom_my_total_count = count($custom_my_query); if( $custom_my_query->have_posts() ) { while ($custom_my_query->have_posts()) : $custom_my_query->the_post(); ?> <a href="<?php echo get_permalink();?>"><?php echo get_the_title($post->ID);?></a> <?php endwhile; } wp_reset_query($custom_my_query); // Restore global post data stomped by the_post(). } 
0
source share

All Articles