get_post_meta
is your friend.
get_post_meta( int $post_id, string $key = '', bool $single = false )
Retrieve post meta field for a post.
Note that custom fields are named post meta internally.
e.g.
$key_1_value = get_post_meta( get_the_ID(), 'key_1', true );
// Check if the custom field has a value.
if ( ! empty( $key_1_value ) ) {
echo esc_html( $key_1_value );
}
Be warned though, it’s tempting to store everything as a post meta, until you have to search for all posts with X meta with Y value. At this point X should have been a custom taxonomy, and your sites speed will tank massively.
Related Posts:
- How to change permalink structure for custom post type and it’s taxonomies?
- Conditional for single-{post-type}.php
- Add Content to Page without shortcodes
- How to build a complex page structure
- Proper way of making custom post type landing page or archive page
- rewrite get parameter with custom post type
- modify all posts of a category to “no comments allowed”
- How to get_queried_object on multiple objects?
- How to not allow custom roles to edit published custom post types?
- Count number of posts which exist in 2 taxonomies?
- Change permalink structure for custom post type
- Pagination gives 404 error
- How can I add columns to custom post tables
- wordpress 3.4 template files in subdirectories
- I am trying to output portfolio items with a picture. This code doesn’t seem to be working. What am I doing wrong?
- Help splitting a custom post type archive into “past” and “upcoming”
- Count all comments of a custom post type
- Custom fields in Permalinks?
- Custom taxonomy template for multiple custom post types
- How to debug a blank page?
- Conditional tags don’t work
- How can I create a custom meta box to add an mp4 video to a page?
- Add/Remove current_page_parent class
- Pull a post based on a meta value in a custom post type
- Dynamic page outside WordPress
- Custom post type permalinks
- Importing posts from XML into custom post type
- Use different taxonomies in different custom post types’ permalinks?
- Ordering posts in Search & taxonomy by post_meta
- Custom Post Type doesn’t show Draft and Trash Options
- How to query_post custom posts within default taxonomy?
- A question on creating filters for custom posts using taxonomy
- WordPress Custom Post Type Permalinks dynamic term slugs
- WordPress comments_open for specific user role or post type
- Restrict Access to Posts based on Custom User and Post Meta Data
- Static apple-app-site-association file with wordpress
- How to define which register_post_status goes to which register_post_type?
- Is it possible to have a custom post type with feed but without the archive?
- Assign Custom post to Custom Taxonomy
- Show post with thumbnails only
- How to add custom taxonomy in custom post type permalink?
- Add parent post to Custom Post Type [closed]
- Delete “Post Published. View Post” for custom post type
- How to add/edit advanced custom fields on custom post type’s WordPress REST API?
- What’s the name of the custom post type yearly archive template?
- Query custom post type based on post id and custom field value
- Changing slug of all posts
- Share root slug for Child Page and Custom Post Type (prioritizing child pages over posts)
- Pull in taxonomy field of custom post type in new query
- Use the custom post type archive for taxonomies?
- Apply template by path/slug related to custom post type?
- WP Query results showing posts outside of category ID
- Taxonomy template page not working
- How to count other posts not having specific taxonomy terms?
- How do I disply an array inside a custom post type?
- Is there a way to group specific CPTs under a single dashboard menu item?
- Running a custom query inside another cpt single and trying to grab a variable
- Under What Conditions Can I name my CPT the same as my CPT Page?
- Metabox does not show in custom post type
- How can I tell if I’m on a custom post type archive page?
- Can’t Get Parent and Child Categories of Custom Taxonomy to Display
- Query all posts under one taxonomy? Why is my code not working?
- Custom rewrite rule takes place AFTER the generic category rule
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- How to Enable Ascending or Descending In WordPress Default Built-in Loop
- How to add Support to show Fullwidth Featured Image of Custom Post Types in WordPress.?
- How to fix the Post Preview Button (CPT & map_meta_cap)
- Fetch data from two custom post types and create multidimensional array for output to html table
- Query filter by value in meta_value array
- Search CPT by tag ids
- Custom post type 404 category page
- Expire post to draft by date-picker custom field
- Edit the default ‘post’ custom post type arguments
- Publishing failed. The response is not a valid JSON response
- How would i insert a value of custom field from Advaced Custom Field into shortcode generated by Gravity Forms [closed]
- Auto generate excerpt from ACF field on a CPT that does not support excerpt or content
- ‘Simple’ Reservation System
- Combine multiple separate lists into one
- Custom post type, next and previous links by page title
- Imported posts for cpt are imported as scheduled, not published [SOLVED]
- Add specific route for Custom Post Type (add/edit…)
- How do I control what template is shown based upon Taxonomy Term?
- How to add a custom button to each field of a Custom Post Types Admin Screen
- Custom Field to post_title
- Stripe multiple transactions
- Most efficient way of showing children posts?
- Capabilities and mapping required for a role to be able to edit other’s posts of a custom type, BUT only be able to edit their own blog posts
- Post Custom & Taxonomy 404 error
- One Post with different content, depending on a Page
- Custom post type and custom taxonomies display
- custom fields not showing before get_header
- Query shopp categories and CPT
- previous_posts_link returns null when querying custom post type
- Custom Post Type Pagination for Bones Theme [duplicate]
- Adding rewrite rules to Custom Post-type mixed with Taxonomy
- fetch meta fields inside a widget
- Inserting two categories
- How to manage a bookstore
- Url rewrite with custom post type and taxonomy
- Custom Post Types Permalink