Wordpress invalid taxonomy

Asked

Viewed 101 times

0

I started a project recently and I can’t "link" my posts with my taxonomies, my code:

$argsProjeto = array(
    'post_type' => 'projetos',
    'orderby'     => 'post_date',
    'post_status' => 'publish',
    'order'   => 'ASC',
    'hide_empty' => false,
    'posts_per_page' => 6,
);

$projetos = get_posts($argsProjeto);

$argss = array(
    'orderby'  => '
    'order'    => 'ASC',
    'taxonomy' => 'tax_projetos',
);

$tax = get_terms($projetos[0]->ID, $argss);

var_dump($tax);

As a return, the var_dump showcase:

object(WP_Error)[5371]
  public 'errors' => 
    array (size=1)
      'invalid_taxonomy' => 
        array (size=1)
          0 => string 'Taxonomia inválida.' (length=20)
  public 'error_data' => 
    array (size=0)
      empty

1 answer

0

To get the taxynomy posts need to pass this way:

<?php $terms = get_terms( array( 'taxonomy' => 'tax_projetos', 'hide_empty' => false ) ); ?>
<?php foreach( $terms as $_terms ):

$args = array(
        'post_type' => 'projetos',
        'post_status' => 'publish',
        'tax_query' => array(
            array(
                'taxonomy' => 'tax_projetos',
                'field'    => 'slug', // tipo do valor que vc vai passar no terms
                'terms'    => $_terms->slug // slug da categoria, esse slug é gerado quando vc  cria a categoria nova em uma taxynomia
            )
        )
    );
endforeach;
        $postslist = get_posts( $args ); ?>
  • still ta returning me empty, can be a hook error?

  • test like this

Browser other questions tagged

You are not signed in. Login or sign up in order to post.