Sort by custom fields: orderby is only showing the latest page instead of all
-
First off, I am a WordPress newbie… a designer first, developer second- the side of my brain that makes things “pretty” overpowers the side that understands how programming and code works!!!
I have been searching these boards for hours and playing with my template’s code and I just can’t seem to get this right…
I am designing a website that is basically a business directory for a local area. I have set up custom fields for each business’ page:
Business Category, Subcategory, Address, Phone, website, etc.Then on the main page I want to have all of the categories sorted in alphabetical order, followed by subcategories, followed by the businesses underneath, like this:
AUTOMOTIVE
Auto Accessories
Auto Barn
Auto Zone
Auto Parts
Jack’s Auto Parts Inc
New Cars
Johnson Chevrolet
Smith’s Ford
Used Cars
Tim’s Used Cars IncELECTRONICS
Audio
Tom’s Stereo Equipment
Computers
Computer World
Telephones
Mobile Phones Inc.Here’s what I came up with after searching and testing:
<?php while (have_posts()) : the_post(); ?> <?php query_posts($query_string . '&meta_key=business_category&orderby=meta_value'); ?> <h4><?php echo get_post_meta($post->ID, "business_category", true) ?></h4> <div class="list"> <?php query_posts($query_string . '&meta_key=sub-categories&orderby=meta_value'); ?> <h6><?php echo get_post_meta($post->ID, "sub-categories", true) ?></h6> <div class="list-img"> <p id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="" title="Permanent Link to <?php the_title(); ?>"><?php the_content(); ?></a></p> </div> <div class="list-title"> <p id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></p> <p><?php echo get_post_meta($post->ID, "business_address", true) ?><br /> <?php echo get_post_meta($post->ID, "business_town", true) ?></p> </div> </div> <?php endwhile; wp_reset_query(); // Restore global post data ?>
But it only shows 1 category and only the most recent business listing.
What am I missing?
Thanks in advance!!!!
- The topic ‘Sort by custom fields: orderby is only showing the latest page instead of all’ is closed to new replies.