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
- How to display by default only published posts/pages in the admin area?
- How set featured posts using checkbox in post edit screen?
- Post/Page Preview Template
- WP_Query: Why is sticky post not first item in loop?
- using wp_update_post on save_post
- WordPress plugin to publish to multiple remote WordPress blogs
- Display content from a specific category
- how to display full post with pagination on home page
- How to wrap every image in a post with a div?
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Show One Category on Post
- WordPress Delete hook with wp_delete_post function?
- How to use alternate post layout at key points in post loop?
- Order post by year DESC and month ASC
- Showing random content / pictures from earlier posts in a sticky post?
- Do I use custom post type or something else?
- Delete Post From Front-End and attachment permanently
- Custom post type permalinks breaking due to 3.1 bug fix
- ‘Invalid post type’ error when importing from one site to another
- Double count view in archive.php
- Blogroll – Different layout for first post
- How to delete old posts’ edits to save space?
- Different style for most recent article
- Differentiate between posts and pages in search results
- Loop through all product posts?
- Display post category in foreach loop with category link
- Displaying Latest Posts on a Page
- Display all posts that were published before full post on single.php
- How to make number of blog posts a custom field?
- WordPress blog or WordPress website
- List custom taxonomy specific to one custom post type
- Hiding Draft Post In Admin
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- Making a custom Pagination for multi page blog post
- List authors with the last post title and order by last post date
- Thumbnail & Category link aside 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?
- Only display sticky post or latest post in custom loop
- How to make a sum of all posts displayed in a loop
- why does wordpress ignore the post args?
- First x post with another template then the others
- Loop doesn’t show title of second post and posts thereafter
- Grid post page on WordPress with Bootstrap, the_excerpt(); Problem
- Loop parent terms {display posts} AND loop child terms {display posts}
- add bootstrap post slider with tabs
- How to add add more properties to WP_Post object in search results loop
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- WordPress custom post type with folder structure in slug
- Add Blog to WP homepage Manually
- How to show all posts by author on buddypress profile with navigation
- Only show first image in foreach loop
- Show custom post with custom categories with specific slug
- How to call posts under a specific category on static front page?
- how to handle the loop using filling bootstrap grid structure?
- datepicker value in mysql
- WordPress loop not working on static front page
- Get latest post from categories
- Display specific posts on home page
- The loop starting at a certain ID
- Simple Custom Metabox Not Saving
- Loop not showing first post
- How to restore deleted post related with deleted users
- Get current taxonomy and display query accordingly
- WordPress Post Deletion Issue
- How Can I Always Display A Particular Post First Using WP_Query?
- MySQL: Possible to replace all of wp_posts.post_content(id#) via UPDATE + REPLACE + SELECT?
- Change modified date to current date when title updated automatically
- How to put the author of the post in the comments?
- How to add a custom class attribute into code wrapper? [duplicate]
- Redirecting wordpress search query to archive page
- Multiple post in One Loop in wordpress
- Diffrent layout for posts [duplicate]
- Customizing URL slugs of Custom Post Type and Taxonomy make posts/pages 404
- Show post excerpt
- Show author bio box
- Use special template for the first post in the loop
- WordPress infinite post cycle problem
- List of authors posts minus very latest
- Querying multiple categories in the WP loop if one of the category IDs is dynamically obtained
- How to retrieve custom field values and save again as array
- show latest authors blog post
- Is there a Standard Format for Clean URLs for Archives of Custom Posts?
- Checking if some condition is matched before inserting post into database
- Why is $_POST Empty in Profile Edit Admin?
- Is there a way to separate wordpress titles from their posts?
- Redirecting posts in WordPress to a specific page
- How remove “recent comments” title without modifying code? [closed]
- When and how will php code in a user made WordPress page be executed?