I’m using the $gas
example variable from your question in my answer below. Sorry for the bad formatting, I’m typing this on my mobile device.
If you’re certain that $gas
will always contain a post ID then the simplest solution is to just do echo ! empty($gas) ? get_the_title( $gas ) : '';
(Ternary operator used here)
Another way is to get the options in your template to a variable and access the resulting associative array with $gas
as the key to get the corresponding array value (label in this case).
$options = get_gas_options('fleettype'); echo $options[ $gas ] ?? '';
(null coalescing operator used here).
Related Posts:
- Filtering custom posts with Ajax
- Get all posts from custom post type and insert in select input as metabox
- How to select one major category (or custom taxonomy) for a custom post type?
- Select menu should display categories and the item’s depth
- Creating select dropdown with parent-level custom post types
- I have 2 post types i need to show the post type contents in 2 select boxes [closed]
- Why is my select meta data not saving?
- Widget: Custom Post Type Post Listing Dropdown on Admin Side
- Add “Select All” to custom taxonomy
- echo selected value from dropdown
- Metabox multiple custom post select -> display selected items?
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- put a list of one post type in other post type to select from it and display selected item in second post type’s single page
- Select Menu for Custom post Type does not save
- Repeatable custom meta select boxes
- Create a page selector using taxonomies
- Issues on saving data from CPT select metabox
- Custom post type for ‘staff’ versus using wordpress user profiles?
- How to get custom post type label and singular label from its slug?
- next_post_link() not working for single custom post type post
- How to set a default format for a custom post type?
- Now can I group custom post types together?
- Exclude add_filter from the admin
- Undefined property: stdClass::$labels in general-template.php post_type_archive_title()
- Sanitizing post content for use in an email
- Genesis Child and Custom Post Type
- Query multiple taxonomy in Custom Post Type
- automatically create taxonomy with same name as post title
- saving custom post type data to different table in wordpress
- Display “Post 2 of 4” on single post page?
- register_post_type – rewrite / feeds, what’s it for?
- WordPress import not importing custom taxonomy
- Why are navigation items saved in the database?
- Filter posts with meta_query NOT IN where value has multiple values
- How to make post sticky in the admin page?
- WP 4.7 broke get_post_type or requires an explicit integer value?
- Remove base slug in permalinks of hierarchical custom post type
- is_main_query() not working for WP REST API
- How can I move a custom taxonomy and its data from one post type to another?
- rewrite custom post type slug in wp admin
- Displaying the type of post (Custom) in a single.php
- If Statement – if current post is a child of a post with a taxonomy
- Get next and previous 3 posts in a term in single post page
- Register widget only page is a singular of custom post type
- I’d like to cycle through existing posts in a post type, showing one per day ordered by title, and starting over when the last is reached
- CPT’s with landing page instead of archive – Url Rewrite?
- How to produce a sub-page-system in WordPress
- How can I add a filter to a particular post format?
- How do you make a custom post type items automatically delete items 3 months after publication?
- get_post_meta is not working inside shortcode
- False Positive on has_post_thumbnail
- Custom Taxonomy not displaying all post
- When updating non-public custom post type it says “Post updated. View Post”
- Enable comments on custom page type – option not showing in “customize” for theme
- How to migrate Custom Field Template to a WordPress Multisite
- How to Query in WordPress which shows Alphabetic Posts?
- Using breadcrumb to return from single-page to list
- How can I lock specific posts (cpt’s) from editing by anyone other than ADMINS
- Why do I need to register my custom post type a second time when flushing rewrite rules?
- How do I Query 2 Custom Post Types?
- Function to erase every post from a taxonomy
- Custom Post Type or Shortcode, What to choose? [closed]
- Building a Data Intensive Website with WordPress
- Custom post type, taxonomy and admin bar
- Change permalink for custom post type?
- Use Author Ids or Names to echo different output inside loop
- Truncate custom post type content
- Group episodes by seasons
- Why this didn’t work if i use get_the_ID(), but works if i pass the numeric id
- Create API’s for custom-post types & custom queries using REST or Graphql
- Display Custom Field or Custom Taxonomy in front page /post/product
- Custom post type defaults to index.php for archive page
- customize Dokan multi vendor: how can i set every Dokan as child of another dokan?
- Why do my custom post types stop displaying over time?
- Create Custom page with custom domain
- WP_Query for custom taxonomies showing posts from non-specified terms?
- Persist meta box choices throughout all posts of same post type
- Rewrite of Custom Post Type doesn’t work with dynamic data
- Make pagination work as a carousel (custom query)
- Question on templates
- How can I load Template file from wordpress plugin
- Getting all custom post taxonomies and exhibiting only part of them
- Custom post type archive false is not compatible with breadcrumbs
- update a posts of other custom post type
- Custome post type “tags” pick default archive instead of custom post type archive
- How to delete comma from the end of results? [closed]
- Single page archive – get coresponding taxonomy and terms
- Custom WordPress URL
- How to assign custom post template to its custom taxonomy terms
- Get post id of permalink for a specific custom post type?
- Displaying custom post types with taxonomy
- Custom taxonomy archive not showing posts of certain child taxonomies
- WP_Query arguments: Loop through custom post type – get all entries except excluded meta_key?
- Custom Post Type Loop breaking php
- Order custom post type is beign ignored
- How do i get the taxonomy term name on the CPT archive page?
- Add a background image into a post [closed]
- Show custom category archive as front page and remove taxonomy slug from urls
- Post object GUID adding http:/
- Meta_query question