Using custom fields in a filter hook

Try get_queried_object() to reference the WP_Post that created the page. if you’re on a single post, it will return the post object if you’re on a page, it will return the page object if you’re on an archive page, it will return the post type object if you’re on a category archive, it will return … Read more

Query Problem – Show posts within category ‘x’ that have a custom field between ‘y’ and ‘z’

May this code help $args = array( ‘cat’ => ‘Category id’ ‘post_type’ => ‘post type’, ‘meta_key’ => ‘enter your metakey’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘age’, ‘value’ => array(min price, max price), ‘compare’ => ‘IN’, ) ) ); $query = new WP_Query($args); $query will contain an Array of … Read more

Exclude custom post type from search by custom field value?

You need to implement a hook for pre_get_posts filter, in which you can set what you need. Pay attention that you should change only search query, so you have to check if is_search() method returns true. The hook should look like this: add_filter( ‘pre_get_posts’, ‘wpse8170_pre_get_posts’ ); function wpse8170_pre_get_posts( WP_Query $query ) { if ( $query->is_search() … Read more

enabling custom fields in admin?

The visibility of custom fields on the post edit screen is controlled on the post edit page. There’s a button called “Screen Options” towards the top of the screen. Clicking that button will display all of the available boxes and panels for the edit page. If custom fields is not visible here, then either your … Read more

Loop through two different sets of custom fields

Your question literally doesn’t quite sound like “combining” loops, that’s usually different thing in WP terminology. Following it literally you already know the part that outputs artist name you want — the_field(‘artist_name’). What probably confuses it in first context is that it’s not really a normal WP loop. Note how that call doesn’t specify which … Read more

WP_Query multiple use of relation and/or

No, meta_query does not support these sorts of complex clauses in a sequence. There are a couple of ways to work around this limitation. One is to filter posts_where_paged and modify the SQL manually. I just spent a couple minutes playing with this option, and it’s not very straightforward – you’ll have to write a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)