I want to check if a variable contains list of post IDs, then I want to query the posts of those IDs only, but if that variable is empty then I want to display all posts.
If I supply IDs to
post__in, then it gets the posts with those IDs, but if it is empty then it should return all posts but it returns no any post.
For example, the following code will get the posts with IDs 1,2,3. However this will return no any post if the $
ids is empty. Shouldn't it return ALL posts in that case? How can I get all posts if
$ids is empty ie.
$ids = ""; ?
$ids = '1,2,3'; $arr = explode("," ,$ids); $args = array( 'posts_per_page' => $number, 'post__in' => $arr, );