Questions tagged [custom-field]
Custom Fields are fields that can hold arbitrary extra information known as meta-data.
3,701
questions
78
votes
2
answers
188k
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',...
67
votes
2
answers
113k
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 ...
56
votes
3
answers
84k
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!
53
votes
7
answers
66k
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....
50
votes
6
answers
38k
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 ...
46
votes
8
answers
161k
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.
41
votes
1
answer
28k
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 ...
38
votes
13
answers
100k
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,
...
38
votes
4
answers
82k
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
42k
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 ...
33
votes
3
answers
36k
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 ( $...
32
votes
5
answers
53k
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 ...
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 (...
31
votes
5
answers
80k
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 ...
30
votes
8
answers
149k
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
58k
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
143k
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 ...
27
votes
5
answers
43k
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 = ...
21
votes
3
answers
54k
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 ...
21
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 ...
19
votes
2
answers
77k
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
7k
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.
16
votes
2
answers
90k
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' => __('...
16
votes
1
answer
19k
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 ...
14
votes
2
answers
25k
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 ...
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 (...
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? ...
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 ...
13
votes
4
answers
19k
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 ...
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?
13
votes
5
answers
18k
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 ...
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 ...
12
votes
1
answer
274
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 ...
12
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 ...
12
votes
2
answers
31k
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
4
answers
9k
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 ...
11
votes
5
answers
18k
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 ...
11
votes
5
answers
31k
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\...
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
5k
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 ...
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?
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 ...
11
votes
4
answers
2k
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
3
answers
10k
views
Do_Shortcode not working for Embed
I'm trying to use Custom Field types to embed Youtube videos in a more organized fashion and using the Do_Shortcode() would seem to work perfectly, however this:
<?php echo do_shortcode('[embed]...