Whats the wrong with this query?

   $args = array(
   'category__not_in' => 1,
   'post_status' => 'publish',
    'numberposts' => 1,
   'tax_query' => 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';

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...

  • there are some attributes inside, that are invalid (year, month, day, hour, minute, second), plus nobody knows, how you define your $original_author variable. try to strip them all off and see, if you get closer to your goal.. tax_query itself looks good to me.. – honk31 Jun 7 '18 at 14:20
  • I edited my question... The code still not working... – Galgóczi Levente Jun 7 '18 at 14:28
  • and you want the query for POSTs correct? have you tried WP_Query in favor of get_posts? – honk31 Jun 7 '18 at 14:37
  • I tested now, with WP_Query working... The fault is sure in the code in my question, but I dont now where and why... – Galgóczi Levente Jun 7 '18 at 14:43

I find the solution: Tax_query not working on multisite

(I dont say, that I work with switch_to_blog, because everything is works fine with this function... everything, including postmeta queries, category__not_in, etc., but EXCEPT: tax_query)

So, "you have to register that custom taxonomy in both blogs". <-- so the problem originate from the different themes, when in the current used theme not registered the custom taxonomy. [BUT, DONT NEED TO ADD TERMS TO THIS TAX, only register]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.