286 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
AkinGn says

Hi, right now I’m excluding the portfolio category while retrieving the last blog posts to relevant section @ home page via a code that uses the variable:

$lastposts = get_posts('cat=-1')
1 is the ID of portfolio, but I wonder if there’s a way to exclude the portfolio category with its slug?
1383 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
wpCanyonThemes says

I don’t think you can exclude by slug, but you can do a query to find the category id by it’s slug, and then use that id to exclude it.

But i think the best way to do blog post and portfolio post separation is to create a custom post type for portfolio posts. It will be easier for the theme user to add/delete/modify and it will be easier for you to code it, since you will have to exclude the portfolio category quite often (blog categories listing, archives, widgets like recent posts…) if you don’t use custom post type.

2061 posts
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
Landonw says

Why do you have cat=-1? I think you’re looking for exclude=1… And anyways, I’m not sure if this is possible, but you may be able to find a plugin for it.

1383 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
wpCanyonThemes says

@landow

Putting a negative number in the cat parameter will exclude that category.

A plugin? For such a simple thing? No.

2061 posts
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
Landonw says

Which is why it’s pointless to do so, and preferred to do ‘exclude=1’. And if he REALLY wants it, yes, if a plugin really is necessary.

I’m sure he won’t need to use a plugin though, he could probably do a special query.

286 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
AkinGn says

I don’t think you can exclude by slug, but you can do a query to find the category id by it’s slug, and then use that id to exclude it. But i think the best way to do blog post and portfolio post separation is to create a custom post type for portfolio posts. It will be easier for the theme user to add/delete/modify and it will be easier for you to code it, since you will have to exclude the portfolio category quite often (blog categories listing, archives, widgets like recent posts…) if you don’t use custom post type.

Thanks man, I’ll see about that. And thanks for your suggestion too, landonw.

by
by
by
by
by
by