Querying another post category to match current post and display in loop

if you are adding the custom query into the single template, try working with get_the_category() to get the cat_id for your query; also, get_posts() does not work with if( have_posts() ) etc. example code, using a custom query: <?php $cat = get_the_category(); $cat_id = $cat[0]->term_ID; $cpt_match_query = new WP_Query( array( ‘posts_per_page’ => 2, ‘post_type’ => … Read more

How do I add a relation parameter to my filter query?

Each of your code blocks will overwrite the previous, you need to add to the array rather than replace it: $args[‘tax_query’][] = array( ‘taxonomy’ => ‘region’, ‘field’ => ‘id’, ‘terms’ => $_POST[‘region_filter’] ); relation is AND by default, so you can just omit it, but if you wanted to explicitly set it: $args[‘tax_query’][‘relation’] = ‘AND’;

How can get all users by current user meta?

You can achieve this using get_users function and its meta_key argument as displayed below. $users = get_users(array( ‘meta_key’ => ‘blocking_users’, )); var_dump( $users ); To retrieve it for current user and print it, please use below code. $user_id = get_current_user_id(); $key = ‘blocking_users’; $single = false; $blocking_users = get_user_meta( $user_id, $key, $single ); echo ‘<p>The … Read more

Comapare get_user_meta value

You can use meta_key or meta_query to fetch users where get_user_meta() ‘val’ == 1 Option 1: $users = get_users(array( ‘meta_key’ => ‘val’, // your_meta_key ‘meta_value’ => ‘1’, // value you want to compare ‘meta_compare’ => ‘=’, )); Option 2: $args = array( ‘meta_query’ =>array( array( ‘key’ => ‘val’, //your_meta_key ‘value’ => 1, // value of … Read more

How can I comment comma-separated array values?

No, it’s definitely not okay to comment your code this way. It changes the string, and even though WordPress might strip the incorrect characters and yield the correct pages (it wouldn’t if your “comments” contained comma’s or numbers), it is incredibly unstable. Instead, if you do want to comment them, I would suggest storing them … Read more

get users search not working with array

get_users looks for an exact match for the value in search in the email address, URL, ID, username or display_name fields… it doesn’t look in the first name field. As you can’t search the first name directly, you could instead look for people with a username or display name that starts with it by using … Read more

extract serialized array to use for wp-query

You need to unserialize() if its serialized string. In your case from what I understand you store the array in the user_meta so its serialize it when you store it. but it will unserialize it when you use the get_user_meta so you dont need to unserialize() Your code seems fine. $author_in = get_user_meta($current_user->ID, ‘following_users’, true); … Read more