Loop posts based on permalink term

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 ); … Read more

Get posts in taxonomy randomly

You have syntax error in tax_query. ‘tax_query’ => array( array ( ‘taxonomy’ => $term->taxonomy, ‘field’ => ‘term_id’, // this is default value, so can be ommited ‘terms’ => $term->term_id, ) ) As you can read in Codex, possible values for field parameter are: term_id (default), name, slug or term_taxonomy_id. In this question you can read … Read more

how to get category`s slug in WP_Query loop?

get_the_category() retrieves WP_Term objects for all the categories assigned to the post. You can combine that with wp_list_pluck() to just get the slugs: $categories = get_the_terms( null, ‘project-category’ ); $category_slugs = wp_list_pluck( $categories, ‘slug’ ); $category_slugs will now be an array of slugs for the categories of the post.

Slow Query On Search

This is the query generated by the internal search function on WordPress. It is criticised for being inefficient, and there are a few drop-in replacements available as plugins. You may be able to find something that helps you by doing more research around these. For example: https://themeisle.com/blog/improve-internal-search-in-wordpress/ https://winningwp.com/best-wordpress-search-plugins/ I don’t have a specific recommendation to … Read more

Custom wp-query in wordpress rest api

You can create a route for Rest API using the below code. Simply put this code in your function.php file /* Route For api */ add_action( ‘rest_api_init’, function () { register_rest_route(‘wp/v2’, ‘test’, array( ‘methods’ => array(‘GET’, ‘POST’), ‘callback’ => ‘test’, )); } ); And then simply create a callback function test and put your stuff … Read more