Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
Learning to Display Posts by Taxonomy?

Here is the situation, I have a custom tax called Skill. I want to be able to display posts only with skill set as Japanese from English.

I am trying to learn how to use pre_get_posts hook to modify my get_posts query. Here is my example, however I land with the error:

Notice: Undefined variable: postdata

This is what I have 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 something is wrong with the above query, which I don't fully understand. Any help and please explain what each field of the array is for if possible.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Try this below code this 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;

}
about 4 years ago · Santiago Trujillo Report

0

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

about 4 years ago · Santiago Trujillo Report

0

$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,
            )
        )
    )
);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!