• I am currently trying to put together an index of all posts sorted alphabetically by my custom taxonomy ‘rating’. My code has been applied to a custom page template with some success. Here is an abbreviated version of my code (since the content of all the columns isn’t particularly important here):

    <h1>Fantasy</h1>
      <table>
       <?php /////////////// Fantasy ///////////////
          $args = array( 'numberposts' => 100, 'order'=> 'ASC', 'orderby' => 'title', 'genre' => 'fantasy' );
          $myposts = get_posts( $args );
          foreach($myposts as $post) :
          setup_postdata($post);
          ?>
       <tr>
          <td><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></td>
          <td><?php if(get_post_meta($post->ID, 'Author', true)) {
             echo get_post_meta($post->ID, 'Author', true);
             } ?></td>
       </tr>
       <?php endforeach; wp_reset_postdata(); // END FANTASY // ?>
      </table>

    I have two issues with this:

    1. I have 20+ total genres. This means I have to copy-paste the code a lot, which makes for a clunky, messy template. I can’t think of a better way to do this, though, since some posts are assigned more than one category. If I called up all posts at once and added a ‘genre’ column, each title would only appear once with multiple genres listed beside it rather than multiple times, with a single genre listed each time. Is there a way to solve this that I haven’t thought of, or do I need to continue using my inelegant workaround?
    2. Right now I have sorted my table alphabetically by ‘title’, which works alright for the most part. My issue is that I would rather sort my list alphabetically by my custom taxonomy ‘rating’ (which doesn’t appear in the code above as I haven’t added it to my table yet, sorry!) and thereunder alphabetical by title. I can’t seem to find any examples of people doing something like this. Is it possible?

    Thank you for your help in advance!

Viewing 15 replies - 16 through 30 (of 32 total)
  • Sorry, I don’t see anything that explains the error.

    Thread Starter Rose

    (@eos-rose)

    Thanks for trying. This is just so baffling. I wonder if it could be something to do with my theme? I suppose it can’t hurt to test it out in another theme just to see.

    How many posts do you have that meet the criteria? If too many, are you possibly running out of memory?

    Thread Starter Rose

    (@eos-rose)

    I have 155 published posts. That shouldn’t be too many, should it?

    I don’t think so, but a lot depends on how much memory is configured and what else is using it.

    You said that 50 would work, but 100 would not. That sounds like a memory problem.

    Thread Starter Rose

    (@eos-rose)

    Strange how I was able to make all the posts appear using all that repeating code, but this code resists me. You would think this would method would have less of a memory strain. Memory is something I know absolutely nothing about, so if you think that’s it, I’m at a loss.

    The repeating code only retrieved a subset of the posts at a time, so less memory was required.

    I can’t guarantee that memory is the problem, but I can’t think of anything else other than memory and max execution time that would quit working as the number of posts increases.

    Check the error logs for your site to see if any errors have been reported. If you do not know how to check the logs, contact your hosting service.

    Here is an article that includes some ways to increase the execution time:

    http://wordpress.mcdspot.com/2012/03/20/ways-to-increase-max-file-upload-size-and-execution-time/

    I have created a different, simpler method for doing this query. You can see the results here:

    http://pastebin.com/zhaHafQv

    Thread Starter Rose

    (@eos-rose)

    That worked like a charm! You are so amazing, thank you!

    Thread Starter Rose

    (@eos-rose)

    Odd. I just noticed that it skips a handful of genres in the middle of the list.

    I believe that it skips genres that have no posts. Try adding a test post in one of the skipped genres.

    Thread Starter Rose

    (@eos-rose)

    One of the genres it skipped was the largest one I had (with 44 posts).

    Go to Admin->Posts->Genre and make sure the counts for each genre are correct. Sometimes these counts get messed up.

    If all the counts look correct, do you have any custom post types? The query in the pastebin only looks at a post_type of ‘post’. Take out that line to see if the records may be in a different post type.

    Thread Starter Rose

    (@eos-rose)

    The counts look correct (though what would you do if they weren’t correct?). The skipped genres appeared using the other codes you gave me (well, up to a certain count, anyway). I don’t have any custom post types.

    There are plugins and sql that can correct the counts.

    Next, lets see if the term is even getting returned by get_terms(). Try changing this:

    $terms = get_terms($taxonomy);

    to this:

    $terms = get_terms($taxonomy,array('hide_empty' => 0));
    foreach ($terms as $term) {
       echo "TERM NAME: $term->name COUNT: $term->count<br />";
    }

    This should list out all terms with the count of posts that they are assigned.

    Does this all look correct?

Viewing 15 replies - 16 through 30 (of 32 total)
  • The topic ‘Creating an index of all posts sorted alphabetically by custom taxonomy’ is closed to new replies.