Custom taxonomy query not working

Whats the wrong with this query?

$args = array(
‘category__not_in’ => 1,
‘author’ => $original_author,
‘post_status’ => ‘publish’,
‘year’ => $year,
‘month’ => $monthnum,
‘day’ => $day,
‘hour’ => $hour,
‘minute’ => $minute,
‘second’ => $second,
‘numberposts’ => 1,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘my-custom-query’,
‘field’ => ‘name’, // slug = name, but also dont working
‘terms’ => array ( ‘257’ ) // simple number (dont ID)
)
)
);
$my_posts_by_meta = get_posts($args);
if( $my_posts_by_meta ) :
$clone_ID = $my_posts_by_meta[0]->ID;
else :
$clone_ID = ‘Error Here’;
endif;

If I use this, this works…:

$terms = get_the_terms( $original_post_id, ‘my-custom-query’);
foreach ( $terms as $term ) {
$termID[] = $term->name;
}
echo ‘What I want: ‘ . $termID[0] . ‘</br>’;

Whats the problem with the first code? When I use custom_postmeta with the same code (or I dont use the custom taxonomy), works…

Read more here:: Custom taxonomy query not working

Leave a Reply

Your email address will not be published. Required fields are marked *