Granted, I may be misinterpreting you. Your post is not very clear but …
category__and
will require the posts to be in both categories. It sounds like you need posts in any of the categories. You should be using category__in
so that you get an OR
match on the categories instead of an AND
match.
showposts
is deprecated.
Both category__and
and category__in
accept an array. You are building a comma separated string of categories and then casting it as an array. That is not likely to work as expected.
Build your category array like this:
foreach($categories as $category) :
$catnumber[] = $category->ID;
endforeach;
And query like this:
$args = array(
'category__in' => $catnumber,
'posts_per_page' => 10,
'orderby' => 'rand'
);
http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
Related Posts:
- Redirect to another page using contact form 7? [closed]
- Plugin for changing a post’s category based on it’s post date?
- How to extract images of post and pages excluding header and logo image in wordpress?
- plugin for wp_list_categories with posts
- How use %like% in sql statement wordpress
- Accessing post’s meta data based on user’s click of a post
- Solutions to repost categories into multisite blogs?
- How do I “get the next 10 posts after post_id == x”?
- Calendar Solution: Handling upcoming Dates with Posts?
- Any built-in function to associate a post to category through a plugin?
- Display by Category in Admin
- Recent posts per category loop?
- check uncategorized category by default
- Delete data from custom table when deleting a post
- How to get Recent Post From Each Category with Thumbnail?
- Adding custom post category to categories widget
- automatically set random featured image by category in wordpress on post
- Trending Tags based on post views
- Ger posts from similar tags and categories
- Find And Add Category to Posts
- Retrieve post thumbnails
- WordPress ultra slow if I click on posts?
- How to add character to content of post?
- Insert data in custom table during new post creation
- single.php fires more than once after clicking on any post to view with different post id each time
- Twitter List Tweets and Delicious Links as Posts
- Automatically set posts to NoIndex depending on category?
- hide particular category post from front page only [closed]
- Can i have limit posts on a specific category and automatically remove older ones?
- How to add portfolio category post count in main navigation menu?
- Show a different number of posts per page depending on context (e.g., homepage, search, archive)
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- Restrict access and display for categories
- How to get posts by content?
- Thumb rating for wordpress – top user
- WP get_permalink Return Wrong URL
- Fatal error: Uncaught Error: Call to undefined function get_userdata()
- How to use get_categories() with Event Organiser plugin
- post expire after x days
- Set attached to state
- Use plugin or custom post type for game score functionality
- Bulk Image Uploader to create new post from each image [closed]
- Display comments of users on single page
- Exclude posts from featuring
- WordPress logo upload option in theme panel
- Post query – show posts from specified day and month and whole years
- how do i remove posts from a WP_Query so the pagination is right?
- Get posts from WP_Query and format them on admin_head
- The problem with WordPress Importer
- Using WP Category Lists Plugin to Dynamically Display Category (PHP)
- switched from query_posts to WP_query, not working now?
- Display post lists in 2nd paragraph
- Matching Chapters to a Custom posts [closed]
- WordPress display breadcrumbs using Yoast plugin [closed]
- How to change this WP_Query to get all ProductIDs and not only specific one?
- Preg Match All doesn’t Allow echo first character for WordPress Taxonomy Tags
- Excerpts on category page
- Insert content of a post into another
- External RSS feed to WordPress Portfolio
- how to use in custom single.php template using php?
- Automatically Assign Author to Category [closed]
- Would Gutenberg be considered a PlugIn?
- pagination on data fetched using SQL query
- Loop doesn’t exclude the specified category in home page
- How do I publish portfolio items with a future date?
- How do I rename a category in the menu bar only?
- Flickering sidebar when scrolling page [closed]
- Where Should i write the code for wordpress ajax voting?
- Post status doesn’t update to ‘future’ every time?
- Grab ID from post from plugin and use it to create an object
- WP::is_main_query() Not Working
- Hook Scripts and Styles in WordPress
- WP_Query of Category Not Showing First Post
- How can recognize post’s category?
- how can authors to define custom pages?
- Adding CASE in WP_Query
- Update existing post dates to random dates and time
- Trying to get property ‘ID’ of non-object in /wp-includes/class-wp-query.php on line 4044
- how to show all posts of each category in pages
- How to echo a PHP Code After the Content
- WordPress Product Detail and catalog
- How to allow editors to only edit certain categories?
- Category as Subdomain for One WP Install
- WordPress CPT Url metabox collection
- Identify if the_post hook is being called from the admin post list
- How to Save settings of custom tab product page in admin side in a database?
- How to insert category name above post title in a featured pages plugin?
- Displaying friend’s posts only
- Hidden Some Setting on Post or Page [duplicate]
- WordPress Categories from Plugin
- WordPress list child pages of custom post type
- Is it possible to setup Category wise Subsciption?
- Posts are deleted everyday at night
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- Enforce conditions only for draft posts using WyPiekacz, ignore pending and published posts
- wp_insert_post_data filter to set category
- Embedding BitBucket Code in Posting
- List posts related to category on a div [closed]
- How to pre-set WordPress settings for specific posts?
- How to update a lot of posts on my WP site with additional content?