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
- Display featured posts first, then display all others within a specific category in WordPress
- Prevent publishing of uncategorized posts
- Global variable $post returning incorrect object
- Custom filter in admin edit custom post type responding with invalid post type?
- Add a class to the anchor tag on HTML5 gallery
- How do you use WP slugs for PDF files / media?
- Nesting if statements to echo only one string based on what tag was filtered?
- How to properly loop through these external URLs to get them into the sitemap using this hook
- Creating a related post section based on similar categories
- Input type search in Menu
- Swapping wp_dropdown_categories function with wp_category_checklist
- add_action shortcut?
- Is it acceptable to treat a filter like an action?
- Proper syntax or method for keeping url in modified isotope / category links
- Filter Select results based on selection
- WordPress plugin for nicer looking slugs? Have multiple pages named the same but they get different slugs
- How can I remove a function that has been added to wordpress with add_filter?
- Issue adding sub category programmatically
- What query string parameter is available for index.php, that works for both pages and blog articles?
- How to control WordPress image metadata (using Imagick)?
- Edit incorrect password message WordPress
- How do I add custom bulk actions to multiple custom post types?
- Add data attribute to each li in menu
- Show prices with tax in Woocommerce Mini Cart [closed]
- Ajax category filtering products default show all
- How to exclude category ID from Looper in WordPress
- php script to change slug in post automatically
- how do I get a specific post from a post with a subcategory in WP
- Why does my callback function not work with this custom filter hook?
- WP grandchild categories in nested ul li
- Grab posts by multiple categories
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to show single category archive
- Move category description below post list in blog
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Removing “wpautop” (auto tags) only on certain pages?
- How to pick the default selected value in wordpress dropdown?
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Get page that displays all children of taxonomy parent
- Add filter when image is uploaded?
- Remove the first 5 characters of the_title and orderby that
- Remove a div from RSS feed
- Print last modified date only on posts
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- selected option if current category is the value
- Unique icons next to each WordPress menu item
- get_template_part based upon post’s category
- how to save selected option in variable for rest api category filter
- Setting default category base on theme activation
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Hide subcategories (widget)
- Alert Bar section within WP loop is displaying even though there are no posts
- Let Users Choose Post Categories
- Different post styles depending on category
- Display category name only once inside loop
- Change tinyMCE editor to allow marked content when pasting from Word
- Problem with login form
- How to show only subcategories in parent category not parent category?
- how to show only specific category for a template
- Alter required message using comment form api
- How to debug this search & replace strings snippet?
- Hide Featured Image Meta Box on Editor Screen
- Dilemma of Populating all the categories in a drop down list
- Add item to top of menu using a filter in functions.php
- Display most popular posts of category
- 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
- How to make modifications only to certain elements of an HTML string on the server-side?
- Override a function defined in wp-includes/comment-template.php
- Edit the_category (); for a hierarchical display
- JSON REST API WordPress only showing first 10 categories
- Category title output before opening title tag
- List taxonomy term slugs within shortcode (do_shortcode)
- get taxonomy thumbnail and use it as a variable in code
- Include Parent Term in wp_list_categories
- 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
- Get all categories post is not in
- Get latest post from all categories except one
- Displaying posts based on category