Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

97
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda