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
- Resetting post data to previous loop in nested loops
- Pagination returns 404 after page 20
- Make loop display posts by alphabetical order
- get custom post type by tag
- Does tax_query really beats meta_query in all situations?
- Group posts by custom field
- Get term by custom term meta and taxonomy
- Woocommerce custom loop to show all the products [closed]
- Get the post permalink within the loop but without additional DB query
- How to show the posts of some category first, and then all other
- Pagination stops at page 6
- Paginated HTML Sitemap
- Display link to taxonomy archive only if it has posts with certain custom field values
- How to limit total number of posts in wp query loop?
- Get list of terms that have posts in another term
- Pagination is broken and I need help fixing it
- How to vary post loop results layout and resume?
- WordPress add_rewrite_rule() cannot visit lower url levels
- Get a post from other loop each n-posts in the main loop
- Loop returning only 1 result
- Fetch posts that match term slug first two letters (wp query)
- Stuck in the query loop
- Need to convert string of term ids into comma separated integers for use in an arguments array
- How do I get my custom query to work with search results after the first page?
- Issue with front page navigation after upgrading to 3.4
- Exclude recently updated post from custom WP_Query using multiple loops
- get_posts output always same post
- Get posts from multiple tax terms
- How to use WP_Query() on single.php?
- difference between querying database and using the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- Tax Query only returns for the first of several terms
- Loop increase in while loop not working
- AJAX Breaking Offset Argument In WP Query
- Save (and exclude) posts from loop to use in another loop on page
- Get all posts with empty meta_value
- Loop 3 posts column wise and continue the loop into same columns
- How to get posts by category and by choosing a taxonomy term?
- Getting the permalink to the latest post from a category
- How to restrict search on a certain page to only return results against custom taxonomies?
- Query Taxonomy By Page Title
- How to change the default post type over the loop?
- Query Not working as expected
- Paginate pages with dynamic query
- WP_Query loop doen’t work with my custom taxonomy
- Determine if ID is page or post and query the ID
- get_the_terms has strange result since version 6.0
- get_children() Archive Template
- Generate custom output on URL with directory
- Display related CPT with custom taxonomy
- Populate select list with meta values from all posts of a Custom Post Type
- tax_query not working on custom post type
- WooCommerce WP_Query using tax_query returns no results (0 = 1)
- Bootstrap grid while loop
- WordPress – Form does not filter the results of taxonomies
- How can I use WP_Query to sort ‘event’ custom post type by date?
- Show one post of each custom taxonomy
- Display posts side by side with custom query
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- How to define a custom hierarchy for terms?
- Woocommerce orderby rand with tax_query not random
- Some doubts about how the main query and the custom query works in this custom theme?
- Escaping WP_Query tax_query when term has special character(s)
- Ordering Posts by parent category, name ascending
- Load 3 posts in flexslider slide [closed]
- Issue with WP_Query (need a array of selected ID’s)
- Multiple wp_query loops showing first 5 posts on all pages instead of older posts[Resolved]
- How to exclude posts ordered by comment_count from subsequent wordpress loops using WP_Query?
- Make assigning post to a specific category equivalent to assigning it to all categories
- $query conflicting with other queries in the same page
- WordPress Post Looping? [duplicate]
- Prevent WordPress loop from displaying similar post titles
- Custom WordPress loop, articles not in same order as Array
- Custom query with custom filtering returning incorrect results