Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the query_posts for "Page" item rather than "Post". I want to have the ability to make the "featured" page always on the top, we could add a custom field called "featured_product", if it's eq "1" then display the post as the very first one.

Here is the basic code for the query. Someone help please!?

<?php query_posts(array('showposts' => 1000, 'post_parent' => $post->ID, 'post_type' => 'page', 'orderby' => 'title', 'order' => 'ASC')); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
...                             
<?php endwhile; else: ?>
...
<?php endif; ?>
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

In your query posts array add this:

'meta_key' => (meta key name in database), 'meta_value' => 1

To make it at the top use two queries. One for the top first post and one for the rest of the posts/pages. so your whole query will look like this:

<?php query_posts(array('showposts' => 1, 'post_parent' => $post->ID, 'post_type' => 'page', 'orderby' => 'title', 'order' => 'ASC', 'meta_key' => featured, 'meta_value' => 1); ?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
...                             
<?php endwhile; else: ?>
...
<?php endif; ?>
<?php wp_reset_query(); ?>
<second query goes here as you have it in your post>

Replace "featured" with your key name.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.