Support » Fixing WordPress » Code help for sorting specific category posts by custom field

  • Resolved Daniella



    I created a template to only list posts in the ‘Entertainment’ category. I wanted to list about 3 posts per page and then have the next button at the bottom. The posts have to be sorted in a certain order so I created a custom field. The following code is only listing the first post without the Next button.

    <?php get_header(); ?>
    	<div id="full-content">
            <div class="breadcrumbs">
     <?php query_posts('cat=3&posts_per_page=3'); ?>
    <?php query_posts('meta_key=ent_order&meta_compare=<=&meta_value=100&orderby=meta_value&order=ASC'); ?>
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="clearfloat">
    	<h4><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
    	<?php if ( in_category('3') ) { ?>
               <div class="post-cat-three">
     <?php } else { ?>
               <div class="post">
     <?php } ?>
    		<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    		<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    	<?php endwhile; endif; ?>
    <div class="navigation">
    <div class="alignleft"><?php posts_nav_link('','','&laquo; Previous Entries') ?></div>
    <div class="alignright"><?php posts_nav_link('','Next Entries &raquo;','') ?></div>
    <?php get_footer(); ?>

    Any ideas?
    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • I have not done what you are doing before. But you have query_posts in there twice. Unless something I don’t know about, that doesn’t seem right to me.

    That fixed one of the problems. Thank you!

    What did it fix? Do you need more help? Did you copy over what was in the duplicate query_posts into the other?

    I did copy over what was in the duplicate query posts. Was that the right way to do it?

    Initially I had a template called entertainment.php and a few things were going wrong, especially with page-navi so I deactivated the plugin. Another problem I was having is that the next page link wasn’t working…it would just refresh the current page.

    What I ended up doing was renaming the template category-3.php and I got it to work but haven’t activated page-navi yet. I would like to know why it worked when I renamed the template.

    I have a lot to learn. 🙂

    Thanks for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Code help for sorting specific category posts by custom field’ is closed to new replies.