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

Can’t add classes using jQuery from a JSON string with get_body_class()

get_body_class() is going to return an array of classes, which is then (per code not published in your question) JSON encoded into that comma separated string. While you can manipulate that in JavaScript, the easiest thing to do is implode the string before encoding: $c = get_body_class(‘project’); $c = implode($c,’ ‘); You should have a … Read more

Getting Category Children

The child_of parameter excepts an integer value of the specific term you need to get descendants from. This means that you need to get the ID from the On-going category term and then passing that ID to the child_of parameter. To note, the child_of parameter returns all descendants of the term passed, this includes direct … Read more

How can you query posts by advance custom field when the value is a serialized array? [closed]

I would advise using the built-in ACF functions for this. Elliot has provided a full toolbox for you and documentation for all field types: <?php // Conditional statement (Single Value) if(get_field(‘page_layout’) == “col_1”) { //… } //Conditional statement (Multiple Values) if( in_array( ‘col_1’, get_field(‘page_layout’) ) ) { //… } ?> Check out the ACF documentation: … Read more

How to put an array in wp user query

This sounds like a job for the wp_parse_id_list() function. It will return an array of unique IDs, sanitized with the absint() function: $csv = bp_get_following_ids(); if( 0 !== $csv ) ) { $uids = wp_parse_id_list( $csv ); $user_query = new WP_User_Query( [ ‘include’ => $uids ] ); } where we assume that bp_get_following_ids() returns a … Read more