Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Wordpress Omit One Post from Query

Wordpress Omit One Post from Query
Thread Tools
Moderator
Join Date: Jun 2000
Location: We come from the land of the ice and snow...
Status: Offline
Reply With Quote
Mar 3, 2010, 12:46 PM
 
I have googled til my googler is sore. I have scoured the codex. I am going insane.

I have a featured post from a certain category on the home page. In the prev/next pages, I don't want that post to occur. I can get that to happen by skipping that post ID. However the posts per page then becomes off.

This is the query to include just one post:
$wp_query->query('p=5&paged='.$paged);

Other attributes use =- to mean omit, but p=-5 does not work. Neither does p!=5.

Any clue on the query to use? Do I have to get all MySQL on this and bypass wordpress functions?
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Mar 3, 2010, 02:20 PM
 
Originally Posted by andi*pandi View Post
I have googled til my googler is sore. I have scoured the codex. I am going insane.

I have a featured post from a certain category on the home page. In the prev/next pages, I don't want that post to occur. I can get that to happen by skipping that post ID. However the posts per page then becomes off.

This is the query to include just one post:
$wp_query->query('p=5&paged='.$paged);

Other attributes use =- to mean omit, but p=-5 does not work. Neither does p!=5.

Any clue on the query to use? Do I have to get all MySQL on this and bypass wordpress functions?


Nope, use "post__not_in" w. query_posts():

Template Tags/query posts - WordPress Codex
     
Moderator
Join Date: Jun 2000
Location: We come from the land of the ice and snow...
Status: Offline
Reply With Quote
Mar 3, 2010, 04:20 PM
 
Thanks, I'll give it a go!
     
Moderator
Join Date: Jun 2000
Location: We come from the land of the ice and snow...
Status: Offline
Reply With Quote
Mar 3, 2010, 05:20 PM
 
That was much more complicated than necessary (grumble grumble args array), but it's working now! Thanks!
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Mar 3, 2010, 06:59 PM
 
No problem! I used to concoct my own SQL every one in a while, but I'd find that sometimes I'd paint myself into a corner when I wanted to use a WordPress template tag or some function that only works inside the loop. There might be a way to simulate a WP loop outside of WP, but I've never looked into that. I usually find that once you get past the learning curve that the API does most things that you'll ever want or need.

My only complaint about WordPress is its non MVC design.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:54 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2