A WordPress question. Thanks for your consideration.
Isn't it possible to specify array_column information in meta_query key specification?Learn more
The article has a custom field called premium_users.
The contents are the following array.
$premium_users = get_post_meta ($post_id, 'premium_users'); / * Here's what $premium_users looks like [ ['user_id' =>1, 'age' =>10], ['user_id' =>2, 'age' =>20] ] */
I would like to use this information in a meta_query search as shown below.
While the specified value in meta_query is a user ID as shown below, the target array was stumbled with information called age as shown above.
How can I specify meta_query in such cases?
'meta_query' = array ( array ( 'value' =>get_current_user_id () // I want to specify by user ID , 'key' =>'premium_users', // but here is age , 'type' =>'NUMERIC' , 'compare' =>'LIKE' ), );
Answer # 1
'meta_query' = array ( array ( 'value' =>'%'. substr (serialize (['user_id' =>get_current_user_id ()]), 5, -1). '%' , 'key' =>'premium_users' , 'type' =>'NUMERIC' , 'compare' =>'LIKE' ), );
If you are using a custom field plug-in
It might be JSON, not serialized
user_id value type may be string instead of int
Check it by looking in the DB post_meta table
- php - in wordpress article sort, sort at the end if the custom field is blank
- php - wordpress: tab switching using custom field items
- php - [wordpress] i want to display a specific article belonging to a specific term
- php - i want to hide the editor on the wordpress custom post page
- php - [wordpress] i want to create a list page by term (custom post type)
- php - i want to list my custom profile with the wordpress plugin buddypress
- php - custom post page in wordpress oh, can i have a fixed page as a parent?
- php - [wordpress] i want to display the latest article of a custom post in full text on the top page
- php - [wordpress] i want to make a monthly list with the date entered in the custom field
- php - wordpress custom taxonomy cannot be saved/selected as a tag from the article posting screen of the management screen
- php - [wordpress] to output all posted article titles in the list
- php - [wordpress] i don't know how to control the title of a custom post page
- php - [wordpress] i want to customize the title of the web page
- php - i want to output 2 new articles of custom post type in the form of contact form 7
- php - [wordpress] i want to display the ip address in the comment field
- php - how to require files in a theme with wp tags in wordpress
- wordpress debuglog no longer prints php errors
- php - i started wordpress, but i can't log in
- php - links to the previous and next article list do not work well
- php : The number of products in the woocommerce cart is not updating
- php - i want to display an eye-catching image in wordpress
- php - i want to disable responsive support in the header part, but i can't
- php - i want to output the contents of smart custom fields of wordpress
- php - the number of reviews of wp customer reviews is different from the actual number
- php - check box is it possible to determine whether or not there is a check and branch?
- php - posts and pages cannot be displayed on the wordpress administration screen
- php - wordpress displays the error "notice: wp_enqueue_style was called incorrectly"
- php - [refine search] if the child term is not checked, you want to display the search results that belong to the parent term
- php - if the value is empty, i want to display all terms as search results