Questions tagged [custom-field]
Custom Fields are fields that can hold arbitrary extra information known as meta-data.
337
questions
13
votes
3
answers
7k
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? ...
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
85k
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!
54
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....
31
votes
5
answers
81k
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 ...
47
votes
8
answers
162k
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 ...
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 ...
21
votes
5
answers
26k
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 ...
45
votes
2
answers
36k
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 ...
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 ...
78
votes
2
answers
193k
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',...
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']...
7
votes
1
answer
2k
views
Truncating custom fields
I'm using custom fields to pull a secondary description. I'd like to use the built in WordPress truncate but can't seem to figure it out.
$desc = get_post_meta($post->ID, "youtube-desc", true);
...
51
votes
6
answers
39k
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 ...
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 ( $...
2
votes
1
answer
5k
views
Custom query with category exclusion and post-meta "whitelist"
I have two widgets, one shows News while the other shows everything except News (We'll call the second one Blog). The blog portion is currently working correctly.
The News posts are either ...
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 (...
2
votes
1
answer
3k
views
Order by custom field date?
I've created a category "Expire Soon" and i want to insert and sort the posts by custom field "expiration_date".
I use this code but the posts are sorted by custom field "expiration_date" but not by ...
40
votes
13
answers
102k
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,
...
32
votes
8
answers
153k
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 ...
31
votes
7
answers
37k
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 ...
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 ...
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 ...
10
votes
3
answers
5k
views
Custom Post Type Data in Sidebar widgets?
(note: this question was originally about Custom Fields, but @MikeSchinkel had a better solution involving Custom Post Types)
On my site I have several pages which I want to show the same data in the ...
6
votes
2
answers
9k
views
Order get_terms() By Custom Field
I want to order my categories like I order my pages. I've added an extra field called Order to my taxonomy, but how do I order my terms by this value?
Adding and Saving my Order Value:
/** Add New ...
5
votes
3
answers
7k
views
Many to Many Relationship between Two Custom Post Types
How do I create a many-to-many relationship between two custom post types?
Given type A and given type B, I'd like to be able to show all Bs that relate to a given A, and all As that relate to a ...
4
votes
5
answers
8k
views
Adding Custom Field to Taxonomy Input :Panel
I am looking to achieve something which I figured would be fairly simple to accomplish but it seems there are no real examples available to achieve my needs.
Essentially I have a custom post type of "...
3
votes
4
answers
14k
views
User Profile / Add Custom Fields
Hello: I am trying to add 7 custom fields to the standard Wordpress wp-admin/profile.php page. There are a few site which suggest a simple bit of code to do this, for example:
http://wpengineer.com/...
1
vote
1
answer
5k
views
2 orderby in wp_query with 2 custom fields
I'm triyng to display hotels (taxonomy which i have created) by two 'orderby' with wp_query but i'm not success.
Results looks likes:
Hotel 1 : 2 persons 5 stars
Hotel 2 : 2 ...
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
4
answers
13k
views
Orderby meta_value only returns posts that have existing meta_key
I have the following wp_query:
$args = array(
'post_type' => 'news',
'orderby' => 'meta_key',
'order' => 'ASC',
'meta_key'=>'custom_author_name',
'post_per_page'=>-...
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\...
10
votes
1
answer
15k
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',
...
9
votes
5
answers
10k
views
Sortable Custom Columns in User Panel (users.php)?
I'm using Register Plus Redux plugin to augment a registration form with custom metadata fields. These fields display at the bottom of each user record detail page and they can be retrieved with ...
7
votes
2
answers
5k
views
How to add a checkbox element to attachments editor with example
The code below adds a custom input field to the attachments editor. How can I convert the text input to a checkbox and get/set the value of the checkbox on load and save?
Note: "input" => "...
6
votes
1
answer
2k
views
WP_Query to show post from a category OR custom field
I am looking for a way to show posts that belongs to a specific category or if they have a custom field. If I specify both parameter 'cat' => '9' and 'meta_key' => 'featured' in query arguments ...
5
votes
2
answers
17k
views
Add a checkbox to post screen that adds a class to the title
I'm needing some posts to have different title colors than others, and I figured this would be most conveniently accomplished by some sort of check box on the post creation/edit screen. How would I go ...
4
votes
1
answer
12k
views
Creating Photo Gallery System with Custom Post Type
I'm creating a movie blog using WordPress.
I have Movie and Trailer custom post types and I want to add a Photo feature for this and I want to add a relationship between this photos and Movie CPT.
...
4
votes
3
answers
6k
views
how to filter by last name for custom post
I have a custom post type (speaker) and I would like to load the list of speakers sorted by last name. I can't seem to figure it out. I tried the code from this post: https://stackoverflow.com/...
2
votes
1
answer
2k
views
set and unset the custom field value
While showing all the posts together in admin panel, I have a custom column 'Featured Image'. And this column has a value YesOrNO.
To set the column name : I have inside functions.php:
function ...
2
votes
6
answers
13k
views
Order posts by custom field and if custom field is empty return remaining posts
I have an archive page ordered by a numeric value in a custom field. This returns the ordered posts correctly, but does not display posts that don't have a custom field.
$paged = (get_query_var('...
2
votes
1
answer
4k
views
How to sort CPT by custom meta value (date), and return posts month by month
For future reference:
I am using the great Meta Box Plugin to help expedite meta box creation for my custom post types.
My goal:
To build a highly customizable events section closely resembling a ...
2
votes
1
answer
18k
views
I am trying to create a simple frontend form for posting
i am trying to learn and create some deeper things with Wordpress. My goal is to create a code/script/plugin that will allow me to post from the frontend.
I have seen many plugins, like templatic ...
1
vote
2
answers
4k
views
Rewrite custom post type url's adding meta box values
I've got these custom post types (CPT) and meta boxes:
Movies (CPT)
Genre (Meta box)
Genres (CPT)
If one movie is called Die hard then I want the permalink to be:
/genres/action/die-hard
This is ...
1
vote
2
answers
361
views
List upcoming events, ordered by date in a custom field
I want to display a list of events with dates in upcoming order. Ex:
23 March, 2013,
30 March, 2013
Below is the query I'm using to filter out posts from my database:
query_posts(
'...
1
vote
1
answer
10k
views
Assign/update the custom field value for all posts
I have over 1000 posts. Each post has a custom field XYZ. I'm looking for a function that I can run once that will assign a value of 1 to each of the posts' custom field XYZ. I've had a look at this ...
1
vote
1
answer
8k
views
How to add/save Custom Field in user settings/profile "Checkbox list"
i have been working on a custom system for my site where users can have a seperate account, setting and profile page to make my site a bit more interactive and community type. with some other ...
0
votes
1
answer
8k
views
How to add upload field in a custom taxonomy?
I have a custom taxonomy and I want to add a custom field inside , OK that's seems to be easy but the hardest part is when I want to add a file input type the enctype="multipart/form-data" I ...
0
votes
1
answer
4k
views
Display thumbnail from custom field
I have a custom field called picture. On the media settings page I've set thumbnail size to 100x100. If upload an image called gecko.jpg, WordPress automatically resizes it and generates gecko-100x100....