Sorting posts by custom field – where to add code
-
In resolved topic 203210 Mattifesto said that inserting the following code before the first call to have_posts() in archive.php would sort the posts by a custom field (‘popularity’ in the example, of course).
query_posts(‘&meta_key=popularity&orderby=meta_value’);
I’ve attempted to do this but am clearly inserting the code in the wrong place as it either appears on the published page or causes a PHP error.
I’d be very grateful if someone could show me exactly where I should place the code in the following, from the existing archive.php.
<?php get_header(); ?>
<div id=”content”>
<div id=”contentleft”>
<div class=”postarea”>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
- The topic ‘Sorting posts by custom field – where to add code’ is closed to new replies.