Questions tagged [custom-field]

Custom Fields are fields that can hold arbitrary extra information known as meta-data.

Filter by
Sorted by
Tagged with
74 votes
2 answers
177k views

WP_Query - Order results by meta value

I've checked around and haven't seen an answer which works as of yet. I have a WP_Query with the following arguments: $args = array( 'post_status' => 'publish', 'post_type' => 'listing',...
  • 1,012
67 votes
2 answers
112k views

How can I add an image upload field directly to a custom write panel?

I've added a new page under "Pages" in the wordpress admin, and added several custom fields. I'd also like to be able to add an upload image field to the page editor - is there some way to do this via ...
  • 893
54 votes
3 answers
83k views

Add filter menu to admin list of posts (of custom type) to filter posts by custom field values

This answer is very close to what I am looking to do, but instead I would like to specify a specific custom field and display a select menu of its available values. Thanks!
  • 673
52 votes
7 answers
64k views

getting all values for a custom field key (cross-post)

I know how to get a custom field value for a specific post. get_post_meta($post_id, $key, $single); What I need is to get all the values associated with a specific custom post key, across all posts....
  • 2,415
48 votes
6 answers
37k views

Extending the search context in the admin list post screen

I have created a custom post type and have attached some custom fields to it. Now I would like to the search that authors can perform on the custom post list screen (in the admin backend) to also be ...
  • 1,126
45 votes
8 answers
157k views

Custom query with orderby meta_value of custom field

Aa you know, as of WP3.0 there are options for custom advanced queries, which is great. As of this, some query parameters of custom fields like meta_key, meta_value were deprecated for the new ...
45 votes
2 answers
35k views

How to add a custom field in the advanced menu properties?

Is it possible to add a custom field to menu items? What I want to do is be able to add a field for 'French Navigation Label' and a 'French Title Attribute' in the wp menu interface.
  • 822
41 votes
1 answer
27k views

How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?

Despite the fact I googled a lot, I've not found the answer to a very simple question : I have some posts with a custom field (i.e. supplier_name). I would like to be able to search and filter my ...
  • 411
37 votes
13 answers
96k 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, ...
  • 619
37 votes
4 answers
78k views

what is the correct way to compare dates in a WP query_posts meta_query

I have a query_posts call in a WP template. Through the use of the More Fields Plugin I can give the site admin the ability to create an event (custom post type) and then enter a date which is ...
37 votes
7 answers
41k views

Adding Fields to the Category, Tag and Custom Taxonomy Edit Screen in the WordPress Admin?

The question is "How do I add one or more fields to the Category, Tag and Custom Taxonomy Edit Screen in the WordPress Admin?" This question was asked on the wp-hackers list August 1st 2010 and I ...
  • 37.2k
33 votes
3 answers
35k views

Can I exclude a post by meta key using pre_get_posts function?

I see many people prefer to use pre_get_posts hook instead of query_posts. The code below works and shows all posts which have meta key "featured" function show_featured_posts ( $query ) { if ( $...
  • 351
32 votes
5 answers
51k views

Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title

I'm working on a custom taxonomy term page template where we want the items that are connected to the term sorted by a publication date (custom date field) - and if there are multiple items on the ...
  • 746
32 votes
4 answers
71k views

Advanced search form with filters for custom taxonomies and custom fields

I'd like to build an advanced search form for a specific custom post type, having filters for the custom post types custom fields, custom taxonomies, and for a separate custom post types properties (...
  • 623
31 votes
5 answers
79k views

How to update custom fields using the wp_insert_post() function?

The WordPress function is used for submitting data programatically. Standard fields to submit to incude the content, excerpt, title, date and many more. What there is no documentation for is how to ...
31 votes
7 answers
36k views

Add validation and error handling when saving custom fields?

I have a function that defines a custom field on a post type. Say the field is "subhead". When the post is saved, I want to do some validation on the input, and display an error message on the post ...
  • 5,558
30 votes
8 answers
144k views

How to Add Custom Fields to a Custom Post Type?

Ok, so I have registered a few custom post types and a few taxonomies. Now, for the life of me, I cannot figure out the code I need to add a Custom Field to my Custom Post Type. I need a drop down ...
27 votes
3 answers
57k views

Most efficient way to add javascript file to specific post and/or pages?

I am wondering what the most efficient method is to add a javascript file specifically for a post and/or page. Here are a few solutions I came up with: Switch to HTML editing view and post your ...
27 votes
2 answers
140k views

How to display value of custom fields in page

I have a custom post type called 'software', contained within are various custom fields such as subtitle, price, screenshots, download link, etc. I created a function to allow use of the tinyMCE edit ...
  • 383
26 votes
5 answers
41k views

Can wp_query return posts meta in a single request?

I would like to create a wp_query that would return posts meta inside the posts array. $args = array ( 'post_type' => 'page', 'meta_key' => 'someMetaKeyName', ); // The Query $query = ...
  • 449
21 votes
3 answers
51k views

Multiple orderby values in WP_Query

I'm trying to come up with a query to sort by multiple orderby values. Here's what I have so far: $dept_id=2; $query=new WP_Query(array( 'post_type'=>'wpcontactus', ...
21 votes
5 answers
25k views

Prevent post from being published if custom fields not filled

I have a custom post type Event that contains a starting and ending date/times custom fields (as metaboxes in the post edit screen). I would like to make sure that an Event cannot get published (or ...
  • 439
20 votes
2 answers
29k views

Show Custom Fields in Quick Edit

I have several custom fields that I need my client to be able to edit at anytime. For the sake of convenience, I'd like them to be able to edit these custom fields from the Quick Edit. This way they ...
  • 1,026
18 votes
2 answers
76k views

Where are custom field values stored in the database

I am using the advanced custom fields plugin for posts. I would like to know where custom fields are stored. I checked the wp_posts table. However, I could not find the posts with custom fields. I ...
17 votes
5 answers
20k views

Validating Custom Meta Box Values & Required Fields

Something which I have never seen covered is the best way to validate that specific form fields are filled out correctly for custom post type meta boxes. I am looking to get expert opinions on how ...
17 votes
1 answer
6k views

Max length of meta_value

I was wondering if anyone could tell me the max length of the meta_value field for posts and user meta.
  • 295
16 votes
2 answers
89k views

How to display custom field in woocommerce orders in admin panel?

currently i add a custom billing field in woocommerce by function custom_override_checkout_fields( $fields ) { $fields['billing']['billing_phone_new'] = array( 'label' => __('...
  • 335
16 votes
1 answer
18k views

How do I set the default admin sort order for a custom post type to a custom column?

SOLUTION AVAILABLE HERE I've set up a custom post type called clientarea, and set up several custom columns for it in the admin area - the custom columns are all custom meta fields, as you can see ...
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 ...
  • 1,642
14 votes
1 answer
5k views

Add custom fields to wp native gallery settings

i already searched for solution and found a lot of unsolved or obsolete topics. Custom wordpress gallery option | Custom field for default gallery However, I´d like to add some custom fields (...
  • 141
13 votes
3 answers
6k views

Custom post meta field effect on the performance on the post

I have the posts which have many custom defined meta fields. On posts I am calling them on requirement using get_post_meta. Means for 10 meta fields I am using it 10 times. Am I doing it right? ...
  • 235
13 votes
1 answer
17k views

How to fix missing custom fields after upgrading to WordPress 4.8.1?

I have a custom theme that I used many times on different sites. I also have a custom plugin installed. Prior to v4.8.1 I was always able to see the custom fields in the wp admin when I would edit a ...
  • 503
13 votes
4 answers
18k views

don't publish custom post type post if a meta data field isn't valid

I have a custom post type (CPT) called event. I have a meta box for the type with several fields. I would like to validate some fields before publishing an event. For example, if an event's date is ...
  • 2,072
13 votes
2 answers
24k views

How can I add extra attribute in the 'Page Attribute' section in wp-admin for pages?

I would like to add a select list in the Page Attribute box you see on the right side in the administration interface for pages. Does anyone know if that is possible? Or at least add a custom box ...
  • 2,530
13 votes
1 answer
28k views

How to enable custom fields for pages (if not a bad practice)?

My main page has a intro image beside the main content. I would like to add that image using custom fields. I've noticed that pages don't have. I would like to enable them. Is it a bad practice?
  • 3,777
13 votes
5 answers
17k views

Is there a way to set default custom fields when creating a post?

When I'm creating a new post, just after clicking "Add New", when the post editor shows, instead of having to use the dropdown and choose a custom field to use, I'd like to have some default custom ...
  • 5,991
12 votes
1 answer
6k views

Difference between meta keys with _ and without _ [duplicate]

In wp_postmeta table I noticed that some of the keys are with '_' (underscore) prefix and and some are without _ What is the major difference between these fields and how they can be used while ...
  • 358
12 votes
1 answer
273 views

Is ACF being a honey trap? [closed]

I am an enterprise full stack developer and started using ACF. At first I thought that ACF is a one stop solution for a web site but after researching more on taxonomy I am afraid that using it will ...
  • 245
12 votes
2 answers
30k 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' ...
  • 999
12 votes
4 answers
8k views

Programatically add options to "add new" custom field dropdown

How can I add pre-defined options to the "add new" custom field dropdown? Here's two examples of automatically adding and showing new custom fields: WordPress: Adding Default Custom Fields on New ...
  • 375
11 votes
5 answers
17k views

Custom Post Types: How-to get rid of editor (-meta box)

I'm questioning how i can get rid of the post-editor (visual + html). I tried to not register post type support, and it still appears (de-registering works fine with every other default meta box on ...
  • 50.2k
11 votes
5 answers
30k views

How to get custom post meta using REST API

I am trying to create a REST APIs for my wordpress website which is used for facility listing using wordpress job manager plugin. I have registered my custom post , taxonomies in \plugins\rest-api\...
  • 113
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
4k views

Underscores in custom fields

While trying to perform a WP_Query using meta_query(), I had some trouble because the custom fields created by a plugin had _ in the beginning of its name. Although I noticed it was stored this way ...
11 votes
2 answers
2k views

How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?

I've been playing around with code snippets which add meta data to admin searches. The best snippet I've found was written by Stefano on this question. However, it appears to have 1, annoying bug ...
  • 1,765
11 votes
4 answers
23k views

I want to have my custom field use HTML, how do I do that?

I want to have my custom field use HTML, how do I do that in such a way that I can use a rich text editor to view the content?
  • 3,027
11 votes
3 answers
20k views

Filter by one custom field, order by another?

I have a custom post type "Listing" and I want to get all Listings that have a custom field gateway_value != 'Yes', and order the results by another custom field, location_level1_value. I can get the ...
  • 1,275
11 votes
1 answer
7k views

How to enable revisions for post meta data?

Normally wordpress keeps revision of wp_post table. But for generating a report I need some custom fields to be tracked while any update happens. As custom fields are saved in wp_postmeta table I need ...
  • 111
11 votes
4 answers
1k views

Is there any action filter/hook for validating a custom field before publishing the post?

I have a custom filed called xxxx_url. xxxx_url should be unique. So, before publishing the post, I want to make sure that xxxx_url is unique or not? If it isn't unique, publishing the post should be ...
10 votes
4 answers
7k views

Remove Dimension from wp_get_attachment_image

I am having some issue removing the width and height from my attachment images when using wp_get_attachment_image. This is what I am using to display the image <?php echo $image = ...

1
2 3 4 5
74