if you are adding the custom query into the single template, try working with get_the_category()
to get the cat_id for your query;
also, get_posts()
does not work with if( have_posts() )
etc.
example code, using a custom query:
<?php
$cat = get_the_category();
$cat_id = $cat[0]->term_ID;
$cpt_match_query = new WP_Query( array(
'posts_per_page' => 2,
'post_type' => 'team',
'cat' => $cat_id) );
if ( $cpt_match_query->have_posts() ) :
while ( $cpt_match_query->have_posts() ) :
$cpt_match_query->the_post();
?>
YOUR OUTPUT SECTION
<?php
endwhile;
endif;
wp_reset_postdata();
?>
the above does not take care of the html tags in your code, which also need to be readjusted.
Related Posts:
- Custom taxonomy archive page problem
- WordPress Query Posts From Category Post on Static Page
- How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?
- Optimize CPT-function with a loop
- Custom Post Type Single Loop Outputting Wrong Post
- Custom post type – Loop out in random order but same 15 to appear first… still random
- Show Posts By Custom Field
- How to show the posts list into a static page? Problems to use the loop into a static page
- adding custom meta as well as looping through posts
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- posts_per_page – Repeats only first posts ‘post__in’ array
- Start WP Pagination From Number 1 in URL
- Calling Different Custom Post Timestamps in a table
- WordPress Multisite – Create Default Post and New Category On New Site Install
- Admin – create custom post status and display above table
- custom post template file not shown, instead all the time 404.php
- Set Default Category to Username
- How to allow visitors to filter posts by multiple taxonomies
- How to add tags (custom taxonomy) to post class css?
- Custom order for Mysql array
- show custom post type category dropdown sorting result on same page
- List authors with the last post title and order by last post date
- Listing Specific Categories from Current Post with Depth
- How to exclude visited posts from loop
- Custom Post Type Rewrite To Include Parent Page(s)
- Use two different post_per_page limits with infinite scroll
- Thumbnail & Category link aside post
- wp_query random post
- How to make the first post in the loop be styled like a “new / featured” post?
- “Right Way” to make custom Loop respect reading settings inside admin panel?
- How to setup a query to output posts by groups of five?
- Redirect to another page using contact form 7? [closed]
- Only display sticky post or latest post in custom loop
- How to order posts in an arbitrary order?
- How do I stop the loop from repeating in my category template?
- get_the_category listing in hierarchial order
- how to get post order by post id wp_query?
- How many posts does the loop return?
- Display Posts on Custom Page
- How to make a sum of all posts displayed in a loop
- How to include my own css in post
- Possible to alternate between two loops
- Exclude current custom post on single post
- Wrong post title displayed from loop
- Custom post types related to same custom post type?
- Get Value of Post before
- why does wordpress ignore the post args?
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- Dynamically switch template on click
- Multiple Loops Breaking Pages
- add to end of post in the loop with plugin
- “about us”, ” contact” sections should be article(post) or page in the simple small Business website?
- First x post with another template then the others
- Loop doesn’t show title of second post and posts thereafter
- Is it possible to customize the post according to post format in single.php?
- Customize rel=canonical tag for single blog post
- Change all author links in Blog roll
- a little direction on custom post type
- Grid post page on WordPress with Bootstrap, the_excerpt(); Problem
- disable Tab post on nav-menus page (Admin)
- Showing categories and subcategories with posts
- Second get_permalink inside loop points to wrong URL
- Get the amount of posts on a current page
- Loop parent terms {display posts} AND loop child terms {display posts}
- How to add a class to each individual post?
- add bootstrap post slider with tabs
- How to add add more properties to WP_Post object in search results loop
- Format latest/newest post differently
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Tell WP to use a specific template file in posts
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- relating business and products with custom taxonomy?
- Best Way to Add UnEditable HTML to Posts
- Loop don’t work within single.php page
- Use Click Image to Play Youtube Video in a WordPress Loop
- How safe is it to delete old posts edits to save database space?
- older blog posts not showing in new theme
- Two Custom Post Types with Identical Articles Competing for the same Slug
- Custom Post Type archive
- WordPress custom post type with folder structure in slug
- How to get posts published on the latest date?
- Using setup_postdata() with multi-dimensional array
- The_excerpt() doesn’t parse – how to change that?
- Trying to edit archive.php to only show post extract, with featured image
- Add Blog to WP homepage Manually
- How can I remove the first two words and shorten get_the_title()
- Is codex right on deleting post?
- How to only publish posts with image in it
- How to show all posts by author on buddypress profile with navigation
- Page and post loop same template
- Check if a custom post type has already been created
- Edit multiple custom post types while saving a new or edited post
- ACF to select posts not displaying on blog page
- Create a custom posts page
- Add custom text automatically on each post
- Getting blog pagination to work on page set as front page
- Extracting relevant tags associated with that particular single post only
- Make loop inside slider divisible [closed]
- Why this function doesn’t works without the_post?
- if in category but only with post meta