WordPress.org

Forums

Lists posts by tag using term_order (6 posts)

  1. eebee323
    Member
    Posted 4 years ago #

    How do I display a list of posts all with the same tag but ordered using the number found in the term_order on the wp_term_relationships table?

    I found this code which displays posts by specific category. I just want to do the same thing with tags and using term_order.

    <ul>
    <?php
    global $post;
    $myposts = get_posts('numberposts=14&category=8&orderby=name');
    foreach($myposts as $post) :
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>

    Please let me know if you have any clues.

    Thanks.

  2. MichaelH
    Member
    Posted 4 years ago #

    Hmm. Interesting...didn't test this but:

    <?php
    $taxonomy = 'post_tag';
    $title = 'Tag: ';
    $args=array(
      'orderby'=>'term_order',
      'order'=>'ASC'
      );
    $terms = get_terms( $taxonomy, $args );
    if ($terms) {
      foreach($terms as $term) {
        if ($term->count > 0) {
          echo '<p>' . $title . '<a href="' . get_term_link( $term->term_id, $taxonomy ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> has ' . $term->count . ' post(s). </p> ';
        }
      }
    }
    ?>
  3. MichaelH
    Member
    Posted 4 years ago #

    How do I display a list of posts all with the same tag

    Actually rereading what you said makes no sense in that you can't sort posts with the same Tag using term_order (basically because if you are only using one tag, there's only one term_order assigned to that one tag).

    But you can query posts for a given tag using the query_posts, tag__in argument.

  4. eebee323
    Member
    Posted 4 years ago #

    Maybe I am not understanding what term_order is for. And I see now that it is used in more than one table. I'm talking about the one in wp_term_relationships.

    For example, in this table you could have multiple posts (represented by object_id) tagged with taxonomy_term_id 3 and could these not be ordered 1,2,3,4,5,6, etc. using the term_order in that table?

    Think of it like this: I want to make a list of top 10 news stories from 2005 in a specific order. I create the tag "Top 10 from 2005" and tag posts with that, but how do I ensure that I can display these posts in a certain order?

  5. MichaelH
    Member
    Posted 4 years ago #

    Hadn't noticed that term_order in wp_term_relationships...here's a trac ticket about it though: https://core.trac.wordpress.org/ticket/9547 [edit] adding https://core.trac.wordpress.org/ticket/5857

    Since I'm not sure about that term_order, I'd consider using a custom field such as "post_order" (e.g. 01, 02, 03,... to 10). D

    Didn't test this, but assuming your tag is "2005top10":

    <?php
       $args=array(
       'tag__in' => array('2005top10'),
       'meta_key'=>'post_order',
       'orderby'=> 'meta_value',
       'caller_get_posts'=>1
       );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
    $postorder = get_post_meta($my_query->post->ID, 'post_order', true);
    echo 'post order: ' .$postorder;
    endwhile;
    }
    ?>
  6. eebee323
    Member
    Posted 4 years ago #

    Thanks for all your help.

    I thought of doing a custom field, but I want the ability for each post to belong to multiple tagged lists. (A post might be #5 on 2005top10 and #1 on 2005-stories-about-Animals).

    It seems to me that this particular term_order is a place holder for that sort of functionality but there really doesn't seem to be anyone who uses it yet.

Topic Closed

This topic has been closed to new replies.

About this Topic