Got it to work with:
$queried_object = get_queried_object () ;
and
'terms' => $queried_object->slug,
full code now:
<?php
$queried_object = get_queried_object () ;
$posts = array (
'post_type' => 'writing',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'type',
'field' => 'slug',
'terms' => $queried_object->slug,
),
),
);
$loop = new WP_Query( $posts );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<a href="https://wordpress.stackexchange.com/questions/312112/<?php the_permalink();?>">
<?php the_title('<h2>','</h2>');?>
</a>
<?php endwhile; wp_reset_postdata(); ?>
Related Posts:
- Custom query for certain post type OR another post type with a certain category
- Search custom taxonomy term by name
- Display posts the match taxonomy term linked from wp_list_categoies?
- Why is my WP_Query not working when tax_query terms are an array?
- Move posts to top of WP_Query if in certain Taxonomy?
- How to add terms to my tax_query based off of the current post
- Is it possible to dynamically get queried term AND taxonomy?
- WP_Query tax query part of slug
- Taxonomy Query Relation field not behaving correctly?
- Post loop for all taxonomy terms
- How to get list of posts from permalinks?
- Custom taxonomy.php not working
- How to add tax_query to $args with concatenation
- Get posts in taxonomy randomly
- Function using get_posts() with tax_query not working when called from functions.php
- relation OR instead of AND – Filtered term ID’s in loop
- Show multiple tax_query from 2 or more post_type in a single code
- WP Query should show No Posts when tax_query $args taxonomies don’t have associated posts
- wp_query with meta_query and tax_query
- pages shortcode filtering by category
- How can I get all the posts that are related with a specific taxonomy term?
- Custom taxonomy and query multi conditions
- Empty ‘terms’ in ‘tax_query’ returns an empty array
- Get the tax term in which is a post via wp_query
- Output ACF field dynamicaly within a taxonomy loop [closed]
- tax_query not working properly with get_posts
- Can I force WP_Query to return no results?
- Multiple WP_Query loops with Pagination
- WP_Query and next_posts_link
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- Tax_query terms ID’s using variable
- Get array of posts from the current archive page loop
- How-to exclude terms from the main query the most performant way?
- How can I save an array from a random post sequence for later use?
- In loop: posts have thumbnail AND other variables
- How to order category.php loop by ‘meta_value’?
- Add inline HTML to posts published within last 24hrs
- Querying Multiple Custom Taxonomy Terms
- Display different number of posts from one category on the different pages
- Pagination not working Search posts
- How to extend tag and category “Related Posts” query to custom post_type if the first 2 terms have no posts
- Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Query all posts in a given taxonomy
- Change default ordering of taxonomy terms – pre_get_terms
- Implementing an OR statement to wordpress wp_query
- Get List of all the Authors
- WP_Query, tax_query and term_meta: How to?
- How can i simulate “taxonomy__in” in query?
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- WP_Query loop within WP_Query loop
- Refine search results using WP_Query
- How to pass many ids in post__in?
- How to show subcategories using loop?
- Sub-loop / nested loops Best Practices
- Populate tax_query terms parameter with post term
- Show Sticky Post at the top but do not show again in the loop?
- Any number in meta key (wp query)
- How do I run through a WordPress loop called from a filter function?
- How do I get the title of a category in a custom loop?
- Fastest way of counting posts of a custom post type in a specific taxonomy term?
- Is it a good idea to improve meta query performance by adding tax query?
- WP_Query | Tax_Query Relation | Unable to use ‘OR’ as it then allows all products, help me finish my query?
- How do I exclude the lowest level terms in a taxonomy?
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- Out Of memory issue on post per page parameter
- Check if loop has any categories?
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- How to display an other custom post type in a different custom post type’s archive?
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- Change query from cat id to slug or name?
- Using Wp_Query without the loop?
- Custom WP_Query id
- Assign custom parameter to each post in query
- difference between querying database and using the loop
- WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have
- How does WP generate the default $query in WP_Query based on the URL?
- How to print term name inside wp post loop
- how to get category`s slug in WP_Query loop?
- Does putting queries within loops cause an issue on WordPress?
- Running a custom query inside another cpt single and trying to grab a variable
- Don’t repeat posts from children in parent taxonomy query
- How to make the ‘request’ filter work?
- Strange behaviour of hierarchical taxonomy archive
- How do I stop the same post showing multiple times in a archive?
- Why pagination is not working with tax_query param?
- how to get custom attachment url?
- WP_Query & Duplicate entries
- Query child posts with tax query on parents
- How to break up output of posts for different terms on same page?
- taxquery taxonomy get terms
- Calling a function with WP_Query only ever brings the first result
- query_posts() doesn’t seem to be called in my page
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Next / previous posts link doesn’t show up with Posts 2 Posts
- Carousel Loop only duplicating
- How to show featured post first, then separate loop for other posts
- Multiple Orderby is not working right
- Pagination only showed when no category is set in wp_query
- Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2