I am trying to retrieve specific posts by using slug description.
All posts (in this case products) are stored in “portfolio” where “automotive” is one of the
filters used as a category.
I have already seen some related posts on the web but due to my lack of PHP knowledge couldn’t figure it out so far and thought to give it a try here.
Here is the code used. Any help is appreciated, Thanks!
// Create a new `WP_Query()` object
$wpcust = new WP_Query(
array(
'post_type' => array('portfolio'),
'tag_slug__in' => array('automotive'),
'post__not_in' => array(1366, 1359, 1353),
'orderby' => 'rand',
'showposts' => '4' )
);
Here’s the parameters you can use in your WordPress Query: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
post_type
can be an array or a string.tag
should be astring.
post__not_in
should be an array.orderby
shouldbe a string.
showposts
is DEPRECATED. You need to useposts_per_page
instead. Theposts_per_page
should be an integer.posts_per_page (int) – number of post to show per page (available with Version 2.1, replaced showposts parameter). Use ‘posts_per_page’=>-1 to show all posts (the ‘offset’ parameter is ignored with a -1 value). Set the ‘paged’ parameter if pagination is off after using this parameter.
Your code should be:
May be this can help :-