Skip to main content

All Questions

Tagged with or
Filter by
Sorted by
Tagged with
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 ...
dev-jim's user avatar
  • 1,988
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 ...
tollmanz's user avatar
  • 5,560
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 ...
Picard102's user avatar
  • 933
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, ...
luke's user avatar
  • 649
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/...
cstrouse's user avatar
  • 526
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 ...
Andrew Odri's user avatar
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', ...
mike23's user avatar
  • 6,029
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?
NetConstructor.com's user avatar
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.
Adam's user avatar
  • 361
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 ...
developdaly's user avatar
  • 1,797
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?
Dhiraj Suthar's user avatar
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 ...
Scott B's user avatar
  • 5,696
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 ...
mrwweb's user avatar
  • 10.3k
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'...
onetrickpony's user avatar
  • 13.6k
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( '...
Rizwan's user avatar
  • 357
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:
Mr.Brown's user avatar
  • 1,045
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 ...
SpyrosP's user avatar
  • 515
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?
fxfuture's user avatar
  • 1,337
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 ...
Ana Ban's user avatar
  • 797
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() { ...
Rick Curran's user avatar
  • 1,076
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( '...
Sohrab Taee's user avatar
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 ...
jkupczak's user avatar
  • 1,056
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[...
Tchernitchenko's user avatar
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 ...
majick's user avatar
  • 5,131
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 ...
matt's user avatar
  • 1,662
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?
Julian F. Weinert's user avatar
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 "...
matt's user avatar
  • 1,662
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 ...
Jason Rhodes's user avatar
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 ...
Christine Cooper's user avatar
  • 8,857
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, ...
Bryan's user avatar
  • 291
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 ...
Kelly Hays's user avatar
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' ...
Xaver's user avatar
  • 1,039
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 ...
unfulvio's user avatar
  • 1,824
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. ...
andresmijares's user avatar
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 ...
user1706680's user avatar
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 ...
Nic Warmenhoven's user avatar
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', ...
Andy's user avatar
  • 1,027
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 ...
katemerart's user avatar
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( '...
Philipp Kühn's user avatar
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 ...
Audrius's user avatar
  • 111
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 ...
byronyasgur's user avatar
  • 3,032
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 ...
Syrehn's user avatar
  • 312
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']...
Behseini's user avatar
  • 525
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( ...
dkatwp's user avatar
  • 217
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 ...
user6254's user avatar
  • 125
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 (...
Trevan Hetzel's user avatar
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. ...
matt's user avatar
  • 1,662
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 ...
Wordpressor's user avatar
  • 5,051
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 ...
gmazzap's user avatar
  • 46.3k
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 ...
Dwayne Charrington's user avatar

1
2 3 4 5
54