You can use the category__in
argument:
// use get_the_category( $post_id ) if you are outside the loop
$categories = get_the_category();
if( $categories ){
$related_posts = get_posts( array( 'category__in' => $categories ) );
}
Related Posts:
- Put a link to a category round a hard coded A HREF
- What is an equivalent of single_cat_title for getting the slug of the category?
- Add a specific part of current category page url to shortcode
- Redirect to another page using contact form 7? [closed]
- Allow two posts (from different categories) to have the same slug
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- Get nice name of category from slug (remove dashes of category)
- Multiple Tag Filtering
- Hide a specific category title from displaying on site
- How to filter specific element of an array in wordpress/php?
- Exclude a category slug on pagination
- WordPress using get_term to retreive slug not working as expected
- get_category only returning details for ‘uncategorized’
- dynamically filter by category via sub-menu
- static variable loop not working in WordPress
- What does the token %1$s in WordPress represent [closed]
- Change comments form title on a page by page basis
- Display only text to WordPress loop without loosing the text formatting
- Add custom field to attachments in a specific category
- Remove class that has been added by parent theme
- Display all posts in current category
- append PHP function to the_content
- How to display related posts from parent category
- How can I set custom order use this function
- How do I know what variables are passed in a filter/action and what their meaning is?
- Check if Product is in a Specific Category in Functions.php
- Woocommerce filter cart and category specific quantity [closed]
- Handling Body class based on Template
- Creating a related post section based on similar categories
- Issue adding sub category programmatically
- How do I add custom bulk actions to multiple custom post types?
- Show prices with tax in Woocommerce Mini Cart [closed]
- php script to change slug in post automatically
- Grab posts by multiple categories
- Add filter when image is uploaded?
- Remove a div from RSS feed
- WordPress Gravatar filter is removing my custom attributes
- get_template_part based upon post’s category
- how to save selected option in variable for rest api category filter
- Display category name only once inside loop
- Alter required message using comment form api
- Add filter multiple times using only one master function
- Creating sub-categories via php
- How to edit php code in WordPress Post file?
- Change page title from page using php via php executed from page/post itself
- Define specific category name in PHP
- Edit the_category (); for a hierarchical display
- Category title output before opening title tag
- How to array only one key from another array
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- Filtering a function’ output for a new continued function
- Deleting Certain terms from appearing on the front end as links
- How do I remove a category from a wordpress loop>
- Create page template via functions.php?
- How to have different site identity logos on each page on Astra Theme [closed]
- Add new post in existing categories using wp_insert_post
- How to change logo by category
- Problem with custom loop and wp_list_pluck [closed]
- Remove slugs from custom posts type
- Get the name of menu item with wp_nav_menu
- update_post_meta() not saving data inside of save-post filter
- WooCommerce: Display product categories to make IF statement
- Trying To Get Child Categories To Show, Issue With foreach Loop
- How to add aria role and schema markup to custom walker container
- Define category ID using get_post_meta
- Getting the slug into a variable, how to echo that variable
- apply_filters with several different values?
- User filter posts by year
- How to add a custom filter (by coding) before access one wordpress page ? And where to call the custom filter?
- I need to display posts in subcategory beside posts in main category
- Add Custom Category Description When Empty
- Order category posts by last word of custom field
- Add a product category to a specific product via a button
- Shortcodes not processing inside post content
- I want to hide “sold by” on certain pages with id page 43
- How to Link to category titles if it is in the single post content?
- How can i show specific Category List?
- How to show category just on specific pages?
- How to generate customized filtered output for the gallery
- Add a leading zero to pagination
- How to apply filter
- List categories assigned to a post
- Unable to get Post Category Name and URL
- php string inside shortcode does not work
- Select All not working in a WordPress search filter
- Custom field in title
- Trying to see if page is category or single and displaying title with appropriate heading tag
- WordPress – show all posts + ones with specific tag
- !in_array doesnt recognize category
- WXR XML import is stripping php tags that I need to keep
- category & sub category order issues in wordpress
- AJAX: WordPress filters inside $html do not work as intended
- Fix incorrect related posts code snippet
- Why not showing all post by default in my jquery filter
- Display a list of posts corresponding to a category
- How to create categories out of a list of words?
- Blog Posts not sorted and pagination not adjusted after filtering some category
- Is there a way of displaying related posts from lowest hyrachical order (lowest child category to parent category)
- How to limit number of posts in the certain category and exclude the oldest post automatically
- Custom Filtering date with newsletter