1581 posts
  • Has been part of the Envato Community for over 3 years
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
webdesignerart says

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?

3256 posts
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 more
ParkerAndKent says

Read this:

http://codex.wordpress.org/Function_Reference/register_post_type

There is an “exclude_from_search” parameter when registering post types, so no need to make strange checks :)

Parker

3256 posts
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 more
ParkerAndKent says

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

1581 posts
  • Has been part of the Envato Community for over 3 years
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
webdesignerart says

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
Dude i am not going to exclude from search :P 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 :)

3256 posts
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 more
ParkerAndKent says


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
Dude i am not going to exclude from search :P 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 :)

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

1581 posts
  • Has been part of the Envato Community for over 3 years
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
webdesignerart says



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
Dude i am not going to exclude from search :P 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 :)

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
Which is the post type of your banner/slider slides? Yeah i use bannerspace plugin: http://wordpress.org/extend/plugins/bannerspace/

and this plugin use custom post type.

I want to exclude this banner slider posts from my sitemap.

3256 posts
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 more
ParkerAndKent says

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

1581 posts
  • Has been part of the Envato Community for over 3 years
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
webdesignerart says

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.

by
by
by
by
by
by