I'm using this bit of code to retrieve the object data for post_tag taxonomy.

    $tax = 'post_tag';
    $tax_terms = get_terms($tax);
    if ($tax_terms) {
        foreach ($tax_terms as $tax_term) {
                "$tax" => $tax_term->slug,
                'post_status' => 'publish',
                'posts_per_page' => -1,
                'orderby' => 'title',
                'order' => 'ASC'
            ); // END $args

            $my_query = null;
            $my_query = new WP_Query($args);

            if( $my_query->have_posts() ) {
                echo  'here the taxonomy <em>'. $tax . '</em>  is <strong>'. $tax_term->name .'</strong>';
                while ($my_query->have_posts()) : $my_query->the_post(); 
              <p><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            } // END if have_posts loop
        } // END foreach $tax_terms
    } // END if $tax_terms

it outputs:

// where the taxonomy post_tag is xxxx
// Hello world!

// where the taxonomy post_tag is xxx2
// Hello world!

// where the taxonomy post_tag is xxx xxx3
// Hello world!

Why is this? Would this be classed as a taxonomy or a tag? I'm a bit stumped as to why the tag.php page isn't working on a secondary site in a multisite setup. I've tried renaming a separate page with archive-xxx.php, taxonomy-xxx.php and tag-xxx.php but none seem to work. Also tried WP_Query and it results in this error:

$tag_args = array(
    'taxonomy' => 'post_tag'

if ( $tag_args->have_posts() ...etc...

// Fatal error: Call to a member function have_posts() on a non-object

I'm wanting to display relevant posts associated with the selected tag. It works on the primary blog but not on the second blog in a multisite. Thanks.

  • On your second code block, the reason you may be getting the error Fatal error: Call to a member function have_posts() could be because it doesn't look like you're actually putting your $tag_args in a WP_Query but instead just trying to call a method on an array. – Howdy_McGee Feb 2 '15 at 16:58
  • I've read this several times and can't figure out what you're asking. – Milo Feb 2 '15 at 17:00
  • @Milo based on the first output, it looks like no matter what term he is current on ( in the foreach loop ) it is outputting the same post, but you're right it is pretty unclear. – Howdy_McGee Feb 2 '15 at 17:16

Your Answer

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

Browse other questions tagged or ask your own question.