In your code, if $post_id
were, say, 99, this:
query_posts("showposts=4&post_type=page&post_parent=168&orderby=rand&exclude=". $post_id ."");
would result in this being passed to query posts:
query_posts("showposts=4&post_type=page&post_parent=168&orderby=rand&exclude=". 99 ."");
so, your issue here is '. 99 .'
isn’t a valid value for exclude
.
That said, query_posts
should only be used to alter the main loop in a template. if you want to do additional queries, you should create a new WP_Query
instance.
$args = array(
'post_type' => 'page',
'posts_per_page' => 4,
'post_parent' => 168,
'orderby' => 'rand',
'exclude' => $post_id
);
$related_posts = new WP_Query( $args );
while( $related_posts->have_posts() ):
$related_posts->the_post();
// loop stuff
endwhile;
Related Posts:
- How to return results of a get_posts() in explicitly defined order
- Modify main WordPress loop with a parse_query filter
- How should I intercept the main query and inject custom join / order by / group by criteria
- How to order results by date and meta key?
- Static Front-Page Excerpts
- Is it possible to query_posts using post__in and then Loop through them in the ordered they were queried?
- query_posts() ALWAYS displays something?
- Query Posts Exclude Entire Category
- How to remove a plugin filter’s priority on specific loops (custom queries)?
- Custom loops, sticky posts, and pagination nightmare
- Filter Loop by Custom Field Value
- Using WP_Query and Query_post for the loop?
- Exclude posts by post meta value
- Modify loop but keep the original query, what am I doing wrong?
- When to use WordPress loop or Foreach loop?
- Post per page not working if no category specified
- How exclude 3 latest posts of a category in query_posts
- Exclude current post ID from loop in sidepbar.php
- Calling Posts from Specified Cat
- Most Effective Method? Exclude Category and Number of Posts Per Page
- How do I query based on the modified date?
- Script that gets the first tag of post and query all other posts with the same tag
- How to add an “or” instead of and “and” (&) in a WordPress query?
- Modify main loop query for paged and meta key
- Create a Loop with Posts Ordered by Most Recent Comments
- query_posts and sub pages?
- The_content display a different content from a previous loop
- WordPress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
- Including post data in a sidebar occurring outside of and before the Loop
- Multiple loops with / without sticky posts and different post limits
- query_post by title?
- How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?
- Problem with ‘post__not_in’
- Retrieving 3 latest post from each of 5 different custom post types
- Can’t show comments count per post outside loop
- Alter secondary loop to exclude posts from current page category
- How to sort by meta value?
- pagination in author.php template returns 404 error
- Display one latest post from multiple categories
- How to query ‘posts_per_page’ to display a different blog posts index template?
- query recent posts from several categories
- Example Query Posts Showing the Latest Post with the Featured Image
- How do i paginate query_posts with numeric pagination?
- ‘category__and’ for custom taxonomy?
- Pagination on custom query
- Query posts by specific word on title
- Tricky WP Query
- Change or update WordPress loop based on dropdown selection
- tax_query operator woes
- How can i display the posts per week in a particular month?
- Multiple loops without repeating content
- How To Get Posts With A Specific Word
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Possible to display posts containing a short code ?
- Using ajax with paging and a custom sub-query
- ACF Query meta_values don’t work with ‘offset’
- Make blog page show 10 on first page, 9 on every other page
- Next Posts Prev Posts for Standard post format only
- How to retrieve an array of post IDs by a particular value stored in a custom meta’s array
- query_posts() vs get_posts() multiple loops [duplicate]
- define orderby URL with meta_key=post_views_count
- Query_posts and attachments
- pagination not working for category.php (custom post types in categories)
- Querying posts only if the current page is not paged?
- how to store wordpress loop in array?
- meta_query check for meta value in key which holds an array of values
- 3 random images from custom post type, each in a div with a diffrent class
- Control content before and after custom post type loop
- How to create custom query by keyword in post title?
- Single-page wordpress theme navigation
- meta tag placement for google verification
- show x number of posts from y category on homepage
- Separate First Post Loop
- Frontend form with multiple posts
- Way to cache a query for 24 hrs
- 2 queries with counters
- Make query_post category name dynamic
- Custom Post type showing up in loop, regular posts are not showing up
- Display 3 posts with different HTML markup using a loop
- Meta query stopped working
- Sticky posts don’t show up first in custom loop
- Want Page Descendants when using query_posts post_parent or child_of
- Querying a query
- Duplice post with standard WP loop – fixed by using query_posts() instead
- how to add 4 post in one carousel slide
- Only Show Excerpt After First 3 Posts
- Custom query for custom post type not getting correct post ID
- Create a hierarchical loop at predefined markup requirements
- Modify WordPress loop after it has been run
- display news with pictures 3 small and one large (loop)
- query_posts not working after wordpress 3.7 update
- Is that the query_posts() the real criminal here?
- single.php fires more than once after clicking on any post to view with different post id each time
- Least Number of Loops to Create Custom Homepage?
- Query specific posts from parent by slug rather ID
- How to refine WP-Query with further criteria
- prevent display duplicate titles on main page
- Pagination in category.php not functioning
- Lots of SQL queries
- Limiting the amount of posts this displays