I got it to work by using the following code
function get_gas_options($a) {
$args = array(
'post_type' => 'fleet',
'orderby' => 'ID',
'post_status' => 'publish',
'order' => 'ASC',
'posts_per_page' => -1 // this will retrive all the post that is published
);
$result = new WP_Query( $args );
$title_list[''] = "Assign a Vehicle";
if ( $result-> have_posts() ) :
while ( $result->have_posts() ) : $result->the_post();
$title_list[get_the_ID()] = get_the_title();
endwhile;
endif;
wp_reset_postdata();
return $title_list;
}
Related Posts:
- Querying multiple values from a single key
- Using meta_query, how can i filter by a custom field and order by another one?
- Order by & include array by specific post ids
- WP_Query() show posts that end later than today
- WP_Query orderby custom field then post_date in one query
- Filtering a WP_Query meta_query by numeric values isn’t working
- Ordering posts having multiple post-meta date fields
- Querying custom post type with 2 custom fields (date-range)
- How Can I save multiple records in same meta key?
- filter search result with custom post type meta key
- I can’t set meta_key in my custom post type query
- Using Query Posts With Multiple Post Types And A Taxonomy
- Can’t sort order of wp_query with 2 meta keys
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- How loop through posts based on custom fields
- Automatically adding meta data to posts or multiple query help
- Custom query variable – get wordpress to redirect to nice permalink url
- Filter posts with meta_query NOT IN where value has multiple values
- Displaying Metabox value (custom post type taxonomy)
- Display custom post type taxonomy and month
- CPT Meta Searching
- Filtering by Post Meta Custom Fields – Performance
- Ignore sticky posts if post is not in meta query
- Query that joins the postmeta table twice
- advanced search forms with 3 input text and that the main problem 3 input text
- Setting proper query for multiple custom admin filters
- Sorting Custom Post Type by Meta Value but wont display when set to 0
- How to alter WP-JSON main query or best practise for custom endpoints
- Returning a list of custom post types excluding those without a specific meta_value
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- wp_query check if integer exists in custom field’s array
- Get posts between custom dates
- filter custom post type by meta key in dashboard
- How to store multiple values in 1 meta_key with radio input?
- How to filter wp_list_categories output with some custom post type meta query?
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- How to do WP_Query with two meta fields with orderby clause
- Stuck in Order by more then one
- Meta Query Not Returning Output Despite Having Matching Values
- Meta Query Filtering not working on Custom Meta Box using Radio Buttons
- WP Meta query for a custom post type based on two values
- Using meta_query and tax_query at the same time
- Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
- Admin Custom Meta Box – Pull Last 5 Posts from Custom Post Type
- Limit the post for differents custom post type in the same wp_query
- How to Output which matched meta_keys were found from custom_type_posts?
- filter search custom field query
- How to let users choose where to search for posts?
- Query based on custom fields start and end date
- Custom Post Types — $args vs. labels array
- Get an array wich contains the post_name of every post that has the custom post_type “pelicula”
- Add first letter of titles to array, then compare arrays
- Query Custom Post Types with checkboxes
- Getting a custom post’s custom field based on another custom post’s custom field select
- Check if user has comment on current post
- Get category if used in a custom post type
- get_terms() returns Trying to get property of non-object error for custom taxonomy
- Query for post and costom post_type in same category filtered by meta for post_type
- If meta_value of meta_key is less than today’s date update meta key
- Getting custom post types to properly display alphabetically
- Query Posts, order by meta value
- WordPress giving a 404 page when passing a year argument different than the current year
- Two queries – one with checkbox ticked, one without – comparing meta_query
- How can I loop at a Specific Taxonomy from a custom post type?
- Update value inside array update_post_meta
- Custom archive page for custom taxonomy and pagination issue
- Order admin post list table by meta field, and have posts without the meta field always be at the end of the list
- Get an array of the number of post per year of a custom post type (WordPress)
- Dynamic template page calling shared taxonomies CPT or Plugin post type : how to clone taxonomy for plugin + set up dynamic shortcode
- Using OR relation in meta_query to check for a value before sorting by another
- Filter result of Custom Post Type using meta_query with ACF
- meta_query Where the key value is stored as an array
- Orderby if between two meta fields
- How to select meta key in custom database query
- ACF meta_key and meta_value break loop
- Sort custom post archives by a meta value from a different custom post type?
- Staggering featured post using ‘sticky’
- post type => ‘any’ not applied my custom queries
- How to get the posts that my following users are liked?
- Sort loop by custom field from different post type
- Meta_query by date for Events archive
- How to shows CPT which has specific meta key?
- Querying, storing, and using data from 2 separate custom post types
- Trying to get custom post type attachment images to function in indexed array
- meta query always fails even if data is correct
- Events with multiple event dates + permalink for each date
- WordPress custom field images not getting inserted into array
- Selecting posts older than the current Unix epoch timestamp
- Filter RSS feed for custom post type to events for next 7 days only
- Meta-Box to add multiple items one at a time and on publish save all
- Trying to combine multiple WordPress queries
- taxonomy terms array not working
- Display custom posts in checkbox list
- posting twice from an array?
- WP_Query arguments: Loop through custom post type – get all entries except excluded meta_key?
- loop through custom post-type with two meta_keys
- Querying meta values within an array
- Check for custom field value in different post type than current one and do something
- Order Wp Query by earliest of 3 dates meta query