Get all custom posts with a certain taxonomy

The proper argument to your tax query is terms, not term. You can see this in one of the examples in the Codex: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘people’, ‘field’ => ‘slug’, ‘terms’ => ‘bob’, ), ), ); $query = new WP_Query( $args ); https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters Assuming that your … Read more

Query using string from custom field as array value

Okay anyone wanting to achieve this, the code works. Just save the values in the custom field without quotes. e.g. red, car <?php $list = get_field( “main_attributes” ); $array = explode(‘,’, $list); $args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘style_atrributes’, ‘value’ => $array, ‘compare’ => ‘IN’ ), array( ‘key’ => … Read more

Overriding $wp_query on a template

You are interfering with the main query/loop, which is bad – there is nothing more to say. You can do a custom loop, see the codex article The Loop to start with, or use the pre_get_posts hook, if you want to do something other then the usual behaviour. If you need to toy with $wp_query, … Read more

Show posts of an advanced search form

If I am reading your question right, you need AND not OR for the meta query relation ‘relation’ => ‘AND’, I don’t see where you’ve set the $product_* values either. You should be using $_GET[‘product_color’] (etc), but you need to sanitize that user supplied data. I would use a “whitelist” technique if it were me: … Read more

pass parameters through variable to WP_QUERY

You are wrapping your parameters string in unnecessary layer of quotes: $parameters = “‘category__in=1′”; — wrong $parameters=”category__in=1″; — right It is usually preferable to use arrays for query arguments: $parameters = [ ‘category__in’ => 1 ];

Force WordPress to be more random

I wanted to point out that sometimes in the case of random it’s not the code at all, if you’re using a host that does auto cache or are using a cache plugin, it’s possible the page or the query itself is getting cached and therefor the same results will show. Fixes for this issue … Read more

wp_query get attachments in larger size

If you look at the raw post data… while (have_posts() ) { the_post(); ?> <article id=”post-<?php the_ID(); ?>” <?php post_class(); ?>><?php var_dump($post); ?> </article><?php } You will see that there is nothing in there to specify “medium”, so I went looking. There is a filter on the_content… add_filter( ‘the_content’, ‘prepend_attachment’ ); … that juggles data … Read more

How do I check if there is a tag in the title

Put this in your loop: <?php $title = get_the_title(); $posttags = get_the_tags(); if( $title && $posttags ) { $result = find_tag_in_title( $title, $posttags ); var_dump( $result ); // dump result } ?> Put this in your functions.php file: <?php function find_tag_in_title( $title, $posttags ) { foreach( $posttags as $tag ){ if( strpos( strtolower($title), strtolower($tag->name) ) … Read more