function common_cats($att){
$args = array(
'category__and' => $att['category'], //must use category id
'tag__in' => $att['tag'], //must use tag id for this field
'posts_per_page' => $att['posts_per_page']); //get all posts
$posts = get_posts($args);
$output = "<ul>";
foreach ($posts as $post) :
$output .= "<li>".get_the_title(). "</li>";
endforeach;
$output .= "</ul>";
return $output;
}
add_shortcode('commoncats', 'common_cats');
use [commoncats] where you like to show the output of the above code.
above code will return a list of titles.
Related Posts:
- Update all posts automatically when using post_meta
- Duplicating Table of Contents for Paginated Post
- Using Post ID and Page ID in same function
- Stop WordPress automatically adding tags to post content
- How to protect pages with double authentication: password + email (in custom field)
- How set featured posts using checkbox in post edit screen?
- WordPress removing tags?
- Add a checkbox to post screen that adds a class to the title
- Custom Field in Featured image for A particular post
- Convert custom fields to post categories
- Search & Remove Specific Shortcode From All Posts
- Shortcode Not displayed at the Right Place [duplicate]
- I am trying to create a simple frontend form for posting
- Prevent duplicate posts in wp_insert_post using custom fields
- Automatically added brs and paragraphs?
- HTML code in Custom field
- Better post meta efficiency?
- How to show posts rank based on custom field value
- Add custom field to all posts in specific category
- Adding a Nav menu to post admin
- meta_box or custom_field as a second tinymce post-instance?
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- Specific loop in Shortcode
- Create A Metabox For A Custom Field
- Paragraphs removed when using get_post_custom()?
- get_post_custom stripping styling issue
- Change post format using custom field
- How to add shortcode tags in single.php [closed]
- Populating a page with content from post custom fields
- How to change what the post creation page looks like?
- Sanitizing `wp_editor();` Values for Database, Edit, and Display
- How can I make existing custom fields easier to edit/add in my theme?
- How To Add Perfect Apostrophe And Quotation Mark In WordPress Posts?
- Add custom fields to post programmatically
- Adding variable for post title so post template can include auto-generated link to view on external website.com/{post title}
- How to get Advanced Custom Field Value According using POST ID? [closed]
- How to create shortcode to show the 2 latest posts
- Hide Post comments when displayed via WP_Query
- Autoremove empty custom fields
- How to add a custom field after wp post
- Custom fields on a virtual page
- Remove Shortcode […] from Blog Preview
- What Is meta_id In wp_postmeta?
- Get a custom field of all posts on current blog page
- Only display posts after current date
- Add custom field automatically (add_post_meta) with value based on number of words of article
- Display a post by ID attribute with shortcode
- Global $post not working in OOP function WordPress
- How can I get a post field value using javascript?
- Automatic value for custom fields for posts
- UberMenu list current user’s posts as menu items
- Understanding and using metaboxes in posts
- Query how many items to show in shortcode
- Guest Author – How to display posts on /author/ archive page
- do_shortcode within post query
- WP_Query orderby not working with meta_value_num and menu_order
- How can I sort posts by the date and a custom meta field?
- How to get rid of shortcodes in post content once and for all
- get_the_content(“more…”) returns full text
- Is there a straight-forward way to iterate over all shortcodes in a post?
- How can i display gallery shortcode output under Post text
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Automatically add custom fields value to wordpress post
- Is there a way to notify specific users when new posts are published to specific pages?
- What’s the best way to render Visual Composer in posts, not pages?
- MySql query to get posts with all meta and terms
- Categories list into registration form
- display-posts shortcode attributes have no effect
- Shortcode and whitespace formatting problem
- Add a custom meta box in the post options that loads some html code in the header
- Query Posts With Over 1000 Views
- Cannot retrieve a custom RSS field from posts
- Hooking into the post editing screen for an existing page only
- Query Posts by Custom Field
- Shortcode to display the latest news article within a page
- Redirect to another page using contact form 7? [closed]
- Shortcodes on my website stops working after theme update [closed]
- How to rate a post from Admin Side / Manually?
- How to get ID of the page included with get_page()?
- Customize rel=canonical tag for single blog post
- How to I retrieve the ID from the Posts page?
- How to get a post’s details by shortcode?
- Get post ID from a link
- Create a list of posts with topic headdings
- Add field to user meta table in database when link is clicked
- Hide custom metabox value from custom fields
- Get post meta retrieving wrong value
- Edit multiple custom post types while saving a new or edited post
- Shortcode with ‘year’ parameter
- How come a YouTube link isn’t transformed into a shortcode inside the post content?
- if in category but only with post meta
- Is it possible to add a shortcode below post title?
- WordPress 302 Redirect to Random Product/Post/Page
- Output Post with ACF Fields into other Post
- Saving Post Data in Another Database
- Add two custom fields as a default to the “new post” page.
- After ajax image is outside the “ tag
- Edit custom fields in posts list
- Add multiple meta keys to a post at once
- WP_Query custom field pass the post id