• Hello, I have two post types
    1) dwqa-question – question from DWQA plugin
    2) product – from Woocommerce
    I would like to assign the question from DWQA forum to detail by tags.

    I tried this in functions.php, but the $rquery = new WP_Query($rargs) doesn´t work correctly. Could you help me, please?

    function woo_new_product_tab_content() {
    // DWQA TAGS
    $dwqa_slugs = array();
    $dwqa_tags = get_terms('dwqa-question_tag');
    if (!empty($dwqa_tags) ) {
      foreach((array) $dwqa_tags as $dwqa_tag) {
        $dwqa_slugs[] = $dwqa_tag->slug;
      }
    }
    
    // PRODUCT TAGS
    $tag_slugs = array();
    $product_tags = get_the_terms($post->ID, 'product_tag');
    if (!empty($product_tags) ) {
      foreach((array) $product_tags as $tag) {
        $tag_slugs[] = $tag->slug;
      }
    }
    
    // INTERSECT
    $result = array_intersect($dwqa_slugs, $tag_slugs);
    $rargs = array(
        'post_type' => 'dwqa-question',
        'showposts' => 10,
        'slug' => $result
      );
    
    // WP_QUERY
    $rquery = new WP_Query($rargs);
    
      if ($rquery->have_posts()) {
           echo '<ul>';
        while ($rquery->have_posts()) {
          $rquery->the_post();
          echo '<li>' . get_the_title() . '</li>'; }
          echo '</ul>';
      } else {
        echo 'no posts found';
      }
      // Restore original Post Data
      wp_reset_postdata();
    }
    add_filter('woocommerce_product_tabs', 'woo_new_product_tab');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Problem with WP_query, tags, intersect’ is closed to new replies.