Hi Guys,
My website have all posts in custom post types and unfortunately i am using slideshow plugin which also use custom post type feature. So in my sitemap page all custom post types page are showing which is fine but slider plugin posts are also showing which i don’t want to show in my site map. So how i exclude this post type from foresearch loop.
Here is my site map snipt that show all post type:
foreach( get_post_types( array('public' => true) ) as $post_type ) {
if ( in_array( $post_type, array('post','page','attachment') ) )
continue;
$pt = get_post_type_object( $post_type );
echo '<h2>'.$pt->labels->name.'</h2>';
echo '- ’;
query_posts(‘post_type=’.$post_type.’&posts_per_page=-1’);
while( have_posts() ) {
the_post();
echo ‘
- ’.get_the_title().’ ’; } echo ‘
But i want to exclude my slider banner post type from this foresearch loop.
Any idea to achieve this?
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
Read this:
http://codex.wordpress.org/Function_Reference/register_post_typeThere is an “exclude_from_search” parameter when registering post types, so no need to make strange checks 
Parker
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
Hi,
sorry, I’ve read “forsearch” in your post and I thought you wanted to exclude your slider posts from search 
Anyway, what’s the problem excluding a post type from the query?
In the query arguments set your post_type => array(‘post’,’page’,’attachment’) and so excluding your slides posts…
Then, don’t use query_posts for custom queries, that’s wrong. Use wp_query instead of it:
http://codex.wordpress.org/Class_Reference/WP_QueryParker
ParkerAndKent saidDude i am not going to exclude from search
Hi,sorry, I’ve read “forsearch” in your post and I thought you wanted to exclude your slider posts from search
Anyway, what’s the problem excluding a post type from the query?
In the query arguments set your post_type => array(‘post’,’page’,’attachment’) and so excluding your slides posts…
Then, don’t use query_posts for custom queries, that’s wrong. Use wp_query instead of it:
http://codex.wordpress.org/Class_Reference/WP_Query Parker
basically i list my all posts in sitemap page.
here is:
http://www.avanzasolutions.com/123456/site-map
But on top First show banner slide i don’t want to list this post in sitemap. I found this code to create site map page it works nice but i want bit modification to exclude Banner Slider posts from site map 
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
webdesignerart said
ParkerAndKent saidDude i am not going to exclude from search
Hi,sorry, I’ve read “forsearch” in your post and I thought you wanted to exclude your slider posts from search
Anyway, what’s the problem excluding a post type from the query?
In the query arguments set your post_type => array(‘post’,’page’,’attachment’) and so excluding your slides posts…
Then, don’t use query_posts for custom queries, that’s wrong. Use wp_query instead of it:
http://codex.wordpress.org/Class_Reference/WP_Query Parkerbasically i list my all posts in sitemap page. here is: http://www.avanzasolutions.com/123456/site-map But on top First show banner slide i don’t want to list this post in sitemap. I found this code to create site map page it works nice but i want bit modification to exclude Banner Slider posts from site map
![]()
OK, but you already do this:
if ( in_array( $post_type, array(‘post’,’page’,’attachment’) ) )
so, it’s loading only posts, pages and attachments (why attachments in a site map?)
Which is the post type of your banner/slider slides?
Parker
ParkerAndKent saidWhich is the post type of your banner/slider slides? Yeah i use bannerspace plugin: http://wordpress.org/extend/plugins/bannerspace/
webdesignerart said
ParkerAndKent saidDude i am not going to exclude from search
Hi,sorry, I’ve read “forsearch” in your post and I thought you wanted to exclude your slider posts from search
Anyway, what’s the problem excluding a post type from the query?
In the query arguments set your post_type => array(‘post’,’page’,’attachment’) and so excluding your slides posts…
Then, don’t use query_posts for custom queries, that’s wrong. Use wp_query instead of it:
http://codex.wordpress.org/Class_Reference/WP_Query Parkerbasically i list my all posts in sitemap page. here is: http://www.avanzasolutions.com/123456/site-map But on top First show banner slide i don’t want to list this post in sitemap. I found this code to create site map page it works nice but i want bit modification to exclude Banner Slider posts from site map
![]()
OK, but you already do this:
if ( in_array( $post_type, array(‘post’,’page’,’attachment’) ) )
so, it’s loading only posts, pages and attachments (why attachments in a site map?)
Which is the post type of your banner/slider slides?
Parker
and this plugin use custom post type.
I want to exclude this banner slider posts from my sitemap.
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
Well,
I checked the plugin code and the post_type it registers is bannerspace_post.
This code you have:
if ( in_array( $post_type, array('post','page','attachment') ) )
continue;
basically excludes all posts, pages and attachments… the “continue” skip that loop iteration, it doesn’t mean “execute the next code”. For your knowelede: http://php.net/manual/en/control-structures.continue.php
So, change to this:
if ( in_array( $post_type, array('bannerspace_post', 'attachment') ) )
continue;
and you will exclude attachments and the banner slides.
Parker
ParkerAndKent said
Well,I checked the plugin code and the post_type it registers is bannerspace_post.
This code you have:
if ( in_array( $post_type, array('post','page','attachment') ) ) continue;basically excludes all posts, pages and attachments… the “continue” skip that loop iteration, it doesn’t mean “execute the next code”. For your knowelede: http://php.net/manual/en/control-structures.continue.php
So, change to this:
if ( in_array( $post_type, array('bannerspace_post', 'attachment') ) ) continue;and you will exclude attachments and the banner slides.
Parker
Mate you’re the hero, Very professionally done
Thanks.
