286 posts
  • Bought between 1 and 9 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
  • Turkey
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
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Serbia
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.

2032 posts
  • Has been a member for 4-5 years
  • Bought between 50 and 99 items
  • Exclusive Author
  • 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
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Serbia
wpCanyonThemes says

@landow

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

A plugin? For such a simple thing? No.

2032 posts
  • Has been a member for 4-5 years
  • Bought between 50 and 99 items
  • Exclusive Author
  • 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
  • Bought between 1 and 9 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
  • Turkey
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