All Questions
2,682 questions
63
votes
2
answers
181k
views
Meta_query compare operator explanation
I noticed that there are bunch of operator can be use for compare in meta_query.
However, I am not quite sure what operator I should use, it is somehow confusing like = and LIKE operator.
I would ...
51
votes
14
answers
81k
views
meta_query with meta values as serialize arrays
I'm working on a project in which I'm creating a custom post type and custom data entered via meta boxes associated with my custom post type. For whatever reason I decided to code the meta boxes in ...
49
votes
2
answers
25k
views
Create more Meta Boxes as needed
I'd like users to be able to create and remove additional meta box fields as needed.
For example, say a music podcast with a variable amount of songs played per episode.
The user should be able to ...
40
votes
14
answers
105k
views
Using meta query ('meta_query') with a search query ('s')
Trying to build a search that not only searches the defaults (title, content etc) but also a specific custom field.
My current query:
$args = array(
'post_type' => 'post',
's' => $query,
...
36
votes
5
answers
38k
views
How can I put a custom meta box above the editor but below the title section on the edit post page?
I have a custom meta box for a custom post type that my client wants placed between the title/permalink section and the post editor in the admin panel. Is this possible and if so is there a hook/...
32
votes
3
answers
92k
views
Nested meta_query with multiple relation keys
I am curious whether Wordpress is able to run nested meta_query, with each having different relation keys? As of Wordpress 3.0, tax_query is able to perform this function; I'm wondering whether this ...
31
votes
5
answers
85k
views
How can I create a meta_query with an array as meta_field?
Here are the args for my query :
$args = array(
'post_type' => 'news',
'meta_query' => array(
array(
'key' => 'topics',
'value' => 'sports',
...
31
votes
3
answers
21k
views
Set Default Admin Screen options & Metabox Order
I am desperately looking for some way (any way) to set default "screen options" and metabox order through the functions.php file. does anyone have any help they can provide here?
29
votes
3
answers
35k
views
Only one category per post
How to make each post/page have one and only one category. Categories could have radio box instead of checkbox next to each.
27
votes
4
answers
37k
views
How to set default screen options?
I'd love to be able to hide meta boxes using screen options, instead of removing them or restricting them to user roles, the goal is to just "uncheck" the meta box for the user.
I see how this would ...
23
votes
1
answer
43k
views
Order by multiple meta key and meta value [closed]
How can I set multiple meta keys order by meta value, can any one give me some example?
23
votes
2
answers
18k
views
How to show a custom meta box on the "Quick Edit" screen?
I've used add_meta_box() to add a custom meta box to the WordPress edit window on both pages and posts.
How can I make this meta box also show on the "Quick Edit" screen?
Ideally, I'd like it to ...
22
votes
5
answers
30k
views
Remove Custom Taxonomy Metabox from Custom Post Type Screen
I have two hierarchical custom taxonomies, each on a corresponding custom post type. I would like to remove the metabox for each on the post type's edit screen.
I have read remove custom taxonomy ...
22
votes
4
answers
14k
views
Passing error/warning messages from a meta box to "admin_notices"
I have a simple meta box that updates the post custom fields (using update_post_meta()).
How can I send a error or warning message to the next page after the user publishes/updates the post and doesn'...
21
votes
2
answers
77k
views
meta_query 'compare' => 'IN' not working
First of all, I know it's a duplicate, but none of the older answers were helpful.
I'm searching in posts through post_meta. Here's my code, which currently returns nothing.
$args = array(
'...
21
votes
3
answers
22k
views
How to change default position of WP meta boxes?
Im wondering if there is a way to change the default position of Wordpresses meta boxes such as "featured image" for custom post types without having to drag them manually?
Example:
21
votes
2
answers
63k
views
Add "upload media" button in meta box field
I have a custom post which has a meta tag that needs to be using a file upload (for video files). I am wondering, what is the correct way of adding an "Upload" button that points to the WordPress ...
20
votes
8
answers
13k
views
Disable dragging of meta boxes?
Anyone know how to disable this functionality so the meta boxes can't be repositioned?
18
votes
4
answers
9k
views
Do I need a nonce field for every meta box I add to my custom post type admin?
I'm currently working on the admin page of my custom post type, and I got stuck on deciding whether to add a nonce field again for the second metabox or not. I'm very new to custom post types, and ...
18
votes
5
answers
9k
views
Can I add a Category Metabox to attachment?
I am using register_taxonomy_for_object_type() to add the Category taxonomy field to Media uploads (attachments). I'm using this code to do so:
add_action('init', 'reg_tax');
function reg_tax() {
...
18
votes
5
answers
16k
views
Filtering multiple custom fields with WP REST API 2
I want to filter posts based on multiple acf custom fields with AND relation. Something like this:
$args = array(
'post_type' => 'product',
'meta_query' => array(
'...
18
votes
6
answers
24k
views
Add a Meta Box for uploading a SECOND Featured Image?
I'd like to add a meta box to my posts and page editor that will allow me to upload an image and use it as sort of a SECOND featured image. The idea is that my client will be able to upload an image ...
17
votes
3
answers
35k
views
How to do a meta query using REST-API in WordPress 4.7+?
I am trying to filter by a meta query but no matter what I try I can not make it work.
Basically I want this query in through the rest API:
wp-json/wp/v2/books?meta_query[relation]=OR&meta_query[...
16
votes
6
answers
15k
views
Trigger Javascript on Gutenberg (Block Editor) Save
So I have a metabox which I want to trigger some Javascript when a post is saved (to refresh the page in this use case.)
In Classic Editor, this can be done via a simple redirect hooked to save_post ...
16
votes
2
answers
5k
views
Help Creating a Slideshow Custom Post Type with Custom Meta Boxes?
I need to create a custom post meta box(es) for my custom post type "Slideshow" (this post type is already created). Each metabox will hold the content in each slide slide and save it to ...
15
votes
3
answers
35k
views
Custom Taxonomy as checkbox or dropdown
I have registered a custom tax to my CPT. On the edit screen the tax meta box appears with an autocomplete field.
Is it possible to display it as checkboxes or dropdown instead?
13
votes
1
answer
7k
views
What is the "Advanced" $context in add_meta_box?
In the codex it lists the parameter $context for the add_meta_box as having the following options:
normal
advanced
side
What does "advanced" do? I don't see any difference between it and "...
13
votes
1
answer
6k
views
Is there an easy way to make a meta box have the tabs like the Categories meta box has?
My question is pretty much summed up in the title. I'm dropping a meta box in the New Post / Edit Post admin page, and I want to be able to set it up with tabs like the Categories meta box has. I ...
12
votes
6
answers
10k
views
Removing panels (meta boxes) in the Block Editor
When the Block Editor was added to WordPress, custom and core meta boxes became legacy, meaning, using the remove_meta_box() function won't work when removing meta boxes/panels displayed on the post ...
12
votes
3
answers
22k
views
WP Query Args - Title or Meta Value
How do I query by meta_value or title?
If I set meta_values,
$args['meta_query'] = array(
'relation' => 'OR',
array(
'key' => 'model_name',
'value' => $thesearch,
...
12
votes
6
answers
8k
views
Does Wordpress have a "Form API"?
I do most of my development in Drupal. However I'm working on a Wordpress site and I need to make a form.
Which got me thinking: Is there something like a Form API for WordPress like there is in ...
12
votes
2
answers
33k
views
compare meta_query in get_posts arguments
I like to exclude certain posts with a custom field. So if my_custom_field_ignore isset AND 1 ignore this post. If it's not set include it.
This is what I have
$args = array(
'post_type' ...
12
votes
2
answers
8k
views
Setting admin edit panels & metaboxes positions and visibility for ALL users and admins
My WP 3.3 setup involves several post types and customized edit panels with Advanced Custom Fields plugin (which creates many metaboxes) and other plugins such as SEO metabox panel, Scribu's ...
11
votes
2
answers
19k
views
Metabox with checkbox is not updating
I trying to set a meta_box with a single checkbox, everything goes fine, however if I uncheck it and save the post, it marks again as checked, I've been taking a look but I cannot find my mistake.
...
11
votes
5
answers
16k
views
Meta query terribly slow
I have a custom meta query which is terribly slow or doesn’t even load till the end. With up to three arrays in 'meta_query' the query works fine, with four and up it doesn’t work anymore.
When ...
11
votes
2
answers
11k
views
Custom field/meta populated by dropdown of existing posts?
(My first WP question ever asked! Be gentle!)
I'm building a site that is mostly pages (i.e., static), using WP as CMS. At the bottom of several of the pages, there will appear 1, 2, or 3 "promo ...
11
votes
1
answer
16k
views
Meta query with string starting like pattern
I have a custom WP_Query with the following meta_query:
$meta_query = array();
$meta_query['relation'] = 'AND';
if(!empty($postcode)) {
$meta_query[] = array(
'key' => 'postcode',
...
11
votes
2
answers
12k
views
How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button
I have a custom post type (called contacts).
Since this post type is not working like a post, I don't want to show SAVE DRAFT, PREVIEW, Status, Visibility or Publish Date.
The only options I want to ...
11
votes
2
answers
14k
views
Use REGEXP in WP_Query meta_query key
I know I can use REGEXP in WP_Query like this:
$query = new WP_Query(array(
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'...
10
votes
5
answers
14k
views
WordPress SEO by Yoast: Hide Meta Boxes in Posts for Non-admins
I have multi-author website and I am not very comfortable for allowing all members to enter SEO details in the posts they are publishing. I would like this would be visible only to Administrator of ...
10
votes
2
answers
9k
views
Reset positions of metaboxes in admin
I am writing a theme and in it I have a function which creates two metaboxes. The forth parameter of the "add_meta_box()" function I used can be set to ( high, core, default or low). I want the boxes ...
10
votes
6
answers
16k
views
Change The Title Of a Meta Box
I'm trying to create a function that would allow me to change the title of an established meta box (i.e, change Meta Box title 'Authors' to 'Team', etc.)
I didn't want to use JS or have to unset the ...
10
votes
1
answer
2k
views
What is the index [0] for on post meta fields?
Trying to improve my PHP knowledge through test and try! I am confused on [0] arguments at following WordPress PHP code
global $post;
$custom = get_post_custom($post->ID);
$price = $custom['price']...
10
votes
2
answers
27k
views
ORDER BY custom field value
Based on example here https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/
I'd like to modify the query
$q = new WP_Query( array(
'meta_query' => array(
...
10
votes
1
answer
35k
views
Using meta_query, how can i filter by a custom field and order by another one?
With the following code (in functions.php) my posts (of CPT event) are ordered by _end_date instead of _start_date. What's the proper solution to this as of WP 3.1.3? Of course I'd like to avoid using ...
10
votes
2
answers
9k
views
Query WP REST API v2 by multiple meta keys
Using v2 of the REST API, I'm wanting to query some posts by multiple meta keys. With v1 I was able to format the url like &filter[meta_value][month]=12&[meta_value][year]=2015 and it worked (...
9
votes
4
answers
13k
views
Remove the Featured Image Meta Box
How can I remove the Featured Image meta box? I've tried using the remove_meta_box function and specifying the boxes ID but it doesn't seem to work like it does for the other native meta boxes.
...
9
votes
6
answers
39k
views
How do I get attachment_id?
This is trivial, but I can't really find an answer, I've seen some hints like search in database etc., but this is madness.
Basically, I have a metabox with upload button that allows you to upload or ...
9
votes
2
answers
3k
views
How to make open/closed and hidden/shown metaboxes status saved on a per-post basis?
My real problem is a bit complex, so I'll try here to abstract it and keep it simple.
I'm working on a custom app based on WordPress. I registered a custom post type, let's call it "people" where I ...
9
votes
1
answer
6k
views
How To Remove The "+ Add New Category" Link From A Category Metabox
Inside of a Wordpress category metabox or any custom taxonomy box for that matter there is a link with the text "+ Add New Category" is there a way this link can be removed preferably without ...