query_post on frontpage
-
query_posts('cat=3'and'post_type=page&meta_value=featured&order=DESC');I am trying to be real simple here to have a featured content only on the frontpage. So above the loop I have this and I can’t seem to get both to display both.
Anyone have an idea how to get a post category and a meta page value at the same time to list in the loop?
Thanks
-
The query_posts function is likely interfering with the main loop. For the featured part, try this:
$featured = new WP_Query('cat=3&post_type=page&meta_value=featured&order=DESC'); if ($featured->have_posts()) : while ($featured->have_posts()) : $featured->the_post(); // Regular loop stuff here!!! endwhile; endif;NOTE: I have removed the ‘and’ and replaced with & as per the query_posts format.
This should hopefully do what you’re after. You can copy main loop structure to save time!
thanks but this didn’t work – gave me blank page.
I am thinking I need to call separate then join to show in loop.maybe something like this? But I know this doesn’t work.
$featured_pages = new WP_Query('post_type=page&meta_value=featured&order=DESC'); $featured_post = query_posts('cat=3'); $featured = $featured_post . $featured_pages; if ($featured->have_posts()) : while ($featured->have_posts()) : $featured->the_post(); // Regular loop stuff here!!!$featured = new WP_Query('cat=3&post_type=page&meta_value=featured&order=DESC'); if ($featured->have_posts()) : while ($featured->have_posts()) : $featured->the_post(); // Regular loop stuff here!!! endwhile; endif; wp_reset_query();yeah not working for me.
I can get it to work one or the other but not both post category call and page meta value call in same line.thanks
$featured = new WP_Query('cat=3order=DESC'); if ($featured->have_posts()) : while ($featured->have_posts()) : $featured->the_post(); // Regular loop stuff here!!! endwhile; endif; wp_reset_query();try this once
thanks chinmoy29 I go that to work fine.
It’s combining with a featured page call.
I am using a custom field meta_value=featured on pages to have them be featured as well on the home page. I can make two loops but then I have pages and post not together. I would rather they all be in the same loop so I can sort the lot of them by date.Wondering if I need to add a get_post() call?
ya…all will be working.
Hope
$featured = new WP_Query('cat=3&post_type=page&meta_value=featured&order=DESC');will be working if you addmeta_key= keynamenow code will be
$featured = new WP_Query('cat=3&post_type=page&meta_value=featured&meta_key= keyname&order=DESC');you will change keyname. Ypou will put your key name whose value is featured
The adding of keyname did not work.
This works but you see it is two loops not one. (I’m doing this as a default)
<?php $featured = new WP_Query('cat=3'); if ($featured->have_posts()) : while ($featured->have_posts()) : $featured->the_post(); // Regular loop stuff here!!! ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>><h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'Tweaked' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> <div class="entry-meta"> <?php Tweaked_posted_on(); ?> </div><!-- .entry-meta --> <div class="entry-summary"> <!-- // The Post Thumbnail function is active by default, but this line of php will make it display. --> <?php if( get_the_post_thumbnail($post->ID, 'thumbnail') ) the_post_thumbnail(array(98,68), array("class" => "alignleft post_thumbnail")); ?><!-- //Post Thumbnail Ends--> <?php the_excerpt(); ?> </div><!-- .entry-summary --> </div> <?php endwhile; endif; $featured2 = new WP_Query('post_type=page&meta_value=featured&order=DESC'); if ($featured2->have_posts()) : while ($featured2->have_posts()) : $featured2->the_post(); // Regular loop stuff here!!! ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>><h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'Tweaked' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> <div class="entry-meta"> <?php Tweaked_posted_on(); ?> </div><!-- .entry-meta --> <div class="entry-summary"> <!-- // The Post Thumbnail function is active by default, but this line of php will make it display. --> <?php if( get_the_post_thumbnail($post->ID, 'thumbnail') ) the_post_thumbnail(array(98,68), array("class" => "alignleft post_thumbnail")); ?><!-- //Post Thumbnail Ends--> <?php the_excerpt(); ?> </div><!-- .entry-summary --> </div> <?php endwhile; endif; //Reset Query wp_reset_query();?>yes you need 2 loop .
The topic ‘query_post on frontpage’ is closed to new replies.