Forums

Display posts using custom taxonomy tags (3 posts)

  1. alexduff
    Member
    Posted 5 months ago #

    I have created template pages which I want to be filled in by the use of posts identified by tags. Works perfectly by using

    global $post;
    $postsByTag = get_posts('tag=hnwtag&numberposts=4');
    
    foreach($postsByTag as $post) {
     setup_postdata($post);
     echo '<a href="'. get_permalink().'">'. get_the_title().'</a><br />'.get_the_excerpt().'</a><br />';
    }
    if (have_posts()) : while (have_posts()) : the_post();
     endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    I don't want loads of tags messing up tag clouds, though, so have created a new taxonomy to deal with this, but how can I display the post contents in my template pages via this new taxonomy? Been on this for HOURS!!! Any pointers GREATLY appreciated!!! The new taxonomy is called 'profile', and has tags in it including 'name' and 'school'.

  2. keesiemeijer
    moderator
    Posted 5 months ago #

    Try it with this:

    $args = array(
        'tax_query' => array(
          array(
          'taxonomy' => 'profile',
          'field' => 'slug',
          'terms' => array('name','school')
          )
        )
      );
      $postsByTag = get_posts($args);

    get_posts() makes use of the WP_Query class to fetch posts.
    see: http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters

  3. alexduff
    Member
    Posted 5 months ago #

    keesiemeijer - can't thank you enough!!!!!! Works perfectly - really appreciate this!!!

Reply

You must log in to post.

About this Topic