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?
- What is the easiest way to create a custom field archive?
- Show the author only own types of publications. (JetEngine, Elementor)
- How to check if the post exists in any of the categories?
- ‘Organize Series Plugin’ as muti author feature
- How to Loop Through all Posts and Count Attachments using Get Media Attachments
- Import Instagram post to WordPress blog post
- Problem of encoding characters (apostrophes) in my posts publications
- How to backup single post in wordpress [closed]
- How to get a list of bundled products using wp_query in woocommerce
- How to get all posts belongs to a user between a certain date
- order posts by `meta_key`, Does not display posts that does not have `meta_key`
- Custom post types and ‘new WP_Query’
- Loop doesn’t exclude the specified category in home page
- WordPress Apply filter in plugin causes 500 internal error
- Meta query for comparing two dates
- Display posts of specific category term
- How do I publish portfolio items with a future date?
- wordpress content .php file in an iframe’s src in a wordpress post
- How do I rename a category in the menu bar only?
- Ambrosite Next/Previous Post Link Plus or WP next_post_link to cycle through top level category
- Replacing global wp_query
- Making my plugin create a page?
- Is there a way to make the main page only display a brief description of the full article?
- How to change the post form from plugin?
- WordPress plugin Post Creation [closed]
- Don’t publish/update a post when a plugin finds errors in custom fields
- Allowing users to Sign-up > Login > Post articles that need approval
- Is changing post from category in a large blog a good practice?
- Best/Correct way to add an option to a category
- How to set category correctly for a custom post created by a remote API call?
- Error in pdf generating plugin using FPDF
- How can I automatically download all images from all imported posts, place them on my new host, and replace all the links
- Return multiple values in a shortcode attribute
- posts from multiple post types in one slider
- How to display the featured post on the category page?
- Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
- Migrate posts from category and sub-category via SQL
- woocommerce search by sku and title ajax
- Flickering sidebar when scrolling page [closed]
- Is there a plugin or a way in the wordpress that would let us have different versions of a post or page accessibe to users?
- Moving FB comments at the end of page
- Where Should i write the code for wordpress ajax voting?
- .php file for woocommerce edit category? [closed]
- download button for audio file in post [closed]
- Print posts category or tag as a formatted journal
- how to execute some code after a post is published in WordPress [duplicate]
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Post status doesn’t update to ‘future’ every time?
- Do not duplicate posts with multiple categories in multiple loops
- Add user meta after a user has registered and logged In [closed]
- Function added to hook “new_to_publish” not executing – custom plugin
- Creating an admin meta box to save post as pending
- How to get CPT category checkbox list and show post of selected(multiply) checkboxes via ajax?
- trigger email when post is published by someone a user follows
- Grab ID from post from plugin and use it to create an object
- Mutliple users editing single document in wordspress
- BuddyPress activity on edit post for a CPT
- Article content navigator in wordpress like mbaskool website
- WP::is_main_query() Not Working
- I would like to remove date display on photo preview
- Post deleted in trash [closed]
- Getting a list of the published posts
- How to relate 3 wordpress components with each other (Create database relationships)
- How to add category and subcategory in WordPress custom code?
- Change website directory safely to add a static page on startup
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- If post exists in the database – each time goes on `else`
- Custom Template for wordpress cpt plugin
- Embed PDF into wordpress
- Hook Scripts and Styles in WordPress