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
- Loop a Single Taxonomy and Output all Posts Associated (but also show a message for empty ones)
- Need help with Query Loop. Need to get current taxonomy term and its posts and group them by a different selected taxonomy term
- Running main loop 2 times with conditional statement
- Pagination for blog posts reloading same page [closed]
- Only display post if published in last 24 hours?
- Need to convert string of term ids into comma separated integers for use in an arguments array
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- WordPress | Date not always appear [duplicate]
- Taxonomy order exception for specific term
- Query with meta_query and tax_query together not working properly
- Array as ‘key’ in WP_Query
- How to remove the most recent post from $the_query
- different for loop if screen resolution < 1000px
- WP_Query loop else statement not executing
- Change query from cat id to slug or name?
- How do I get my custom query to work with search results after the first page?
- Using Wp_Query without the loop?
- Is_single() conditional tag returns null in query
- How do I rewrite this loop as a new WP_Query style-loop?
- Transient api Caches confused
- Issue with front page navigation after upgrading to 3.4
- Include current post into loop
- Adding a tax_query to a WP_Query Object
- Custom WP_Query id
- Best choice for multiple loop in page?
- get_template_part causes 500 error
- WP_Query for a taxonomy with different taxonomy types
- Finding WordPress Posts assigned to multiple categories
- WP Query – order posts by meta field first and then order the rest
- How to display the featured image for each post?
- Assign custom parameter to each post in query
- Order or Orderby in tax_query (How to define order of terms in WP_Query)
- How to provide meta_key array to wp_query?
- Wp_query with 2 meta keys and array of meta values
- Adding a html class based on post count
- Check for the main query from the template
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- Using custom taxonomies in a query
- Trying to retrieve random post, getting a page
- Posts in loop all show the same author when there are many authors
- Exclude recently updated post from custom WP_Query using multiple loops
- get_posts output always same post
- Multiple Rows in a using wp_query
- Get posts from multiple tax terms
- How to use WP_Query() on single.php?
- Default permalink structure causing Notice: Undefined property: WP_Query::$post
- How to Order a list of taxonomies? orderby?
- sort and display posts by custom field (wp-query and the loop))
- How to create custom query by keyword in post title?
- difference between querying database and using the loop
- If have posts a week old, display, else display a different loop
- WP_Query – Adding “offset” posts to the end of the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Conditional operator OR not working with custom fields
- How to add custom meta to ‘pre_get_terms’?
- Tax Query only returns for the first of several terms
- Loop increase in while loop not working
- Create a loop on my pages with new “WP_Query”
- Get posts that do not have the same tags as current
- posts archive page – closing WP_Query loop correctly [closed]
- Get Child Category only
- Create a page template for “top rated posts” but show full content and not just a list
- has_excerpt() not working inside wp_query
- wp_query is showing posts from other categories
- exclude product with available tag
- WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have
- Daily drip of posts – based on user ‘startData’ – ordered oldest to newest
- Should I reset $wp_query?
- Meta query compare for ID’s greater than specific ID
- Exclude a Woocommerce product from WP_Query
- WP ForLoop to compare meta information of posts to determine what post to display
- AJAX Breaking Offset Argument In WP Query
- WP_QUERY wrong ammount of posts