try this:
//first get all agents
$agents = new WP_Query(array('post_type' => 'agent', 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'title'));
//then just print out the dropdown:
if ($agents->have_posts()){
echo '<select id="agent">';
while ($agents->have_posts()){
$agents-the_post();
echo '<option value="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</option>';
}
?>
</select>
<script type="text/javascript">
<!--
var dropdown = document.getElementById("agent");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = dropdown.options[dropdown.selectedIndex].value;
}
}
dropdown.onchange = onCatChange;
-->
</script>
<?php
}
Related Posts:
- Custom Taxonomy as Dropdown in admin
- wp_dropdown_categories in custom post type with custom taxonomy
- List custom post types in dropdown
- Conditional two level dropdown filter for custom post type
- Dynamic dropdown custom post list based on dropdown selection
- Set default option in dropdown of WP_Query?
- Dropdown list of a custom post type
- Display custom taxonomy as dropdown list
- Filters post in admin with dropdown select, custom post type
- How to show cutom post labels in options?
- How to convert custom post type based list to a dropdown list?
- Widget: Custom Post Type Post Listing Dropdown on Admin Side
- Multiple level category drop-down from the WordPress dashboard
- Options page – dropdown of users
- How to make custom taxonomy into drop down select in a custom metabox
- Create a Dropdown from Custom Post Type
- dropdowboxes with pre-selected custom fields optios that filters the results according seach needs
- wp_dropdown_pages doesn’t work with post_type argument
- Page Template Dropdown For Custom Post Types
- echo selected value from dropdown
- Unable to display selected post title in frontend from metabox wp_dropdown_pages()
- Add search to ‘Parent’ dropdown
- Set Default Option Value as Blank for Meta Box
- How to selected value default in option list?
- Display Taxonomy Term Children in a Drop Down without Submit Button
- Drop down list with posts within the “add new” page
- Select Venue from dropdown list and reuse stored address information in meta_box
- How to create Custom Taxonomy Search Drop Down for specific Post Type
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- Change dynamically the dropdown list value
- Use output of wp_dropdown_categories($args)
- filter post by date selected in a dropdown in realtime
- Changing an item in drop down after 5 latest posts per taxonomy
- wp_dropdown_pages doesn’t allow me to select more than one custom post type
- Dropdown switching subcategories portfolio
- How to output the content of a Custom Post Type from a drop down form?
- Display posts order by custom post in a dropdown menu
- Query by post title
- WP insert post and custom taxonomy
- Assign a Custom Role to a Custom Post?
- Implementing “Video of the Day” Feature?
- echo value from ‘select’ field type into page template using cmb2?
- Exclude add_filter from the admin
- Undefined property: stdClass::$labels in general-template.php post_type_archive_title()
- Is it proper to create a page just to generate a listing page (eg. for a custom post type)
- Genesis Child and Custom Post Type
- Best way to arrange custom post types by Attributes -> Order metabox value?
- Separate Custom Post Type Taxonomy by Comma
- CSS for Custom Post Types
- Display “Post 2 of 4” on single post page?
- Query post types with multiple keys
- How to generate a sitemap with custom posts (not Google XML)
- Turn query string to sub page
- How to make post sticky in the admin page?
- 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
- Unable to retrieve any posts of CPT in wp-admin
- Rewrite slug for CPT
- Register widget only page is a singular of custom post type
- Which post does a taxonomy term belongs to?
- Remove the parent slug in a CPT URL
- Custom Post Type – No Results Found
- Including metaboxes from custom post types in global search — continued
- How to produce a sub-page-system in WordPress
- Custom posts type for individual pages?
- Custom Taxonomy not displaying all post
- How to Display Posts From Category Within a Custom Taxonomy?
- post-per-page and offset not working
- When updating non-public custom post type it says “Post updated. View Post”
- Published post auto change status to pending after 90 days
- How to retrieve all wordpress posts (specific type) inside a function in php?
- How to migrate Custom Field Template to a WordPress Multisite
- Automatically update slug with latest title within custom post type [duplicate]
- Custom post type, taxonomy and admin bar
- Problem with custom loop navigation inside the blog page
- WordPress giving me the index
- How to customize custom post type’s list table?
- Query to show post current day
- Using ACF values in nested WP queries for CPT with date values in the past
- SELECT custom post type and its meta in SQL
- Trying to list years (for a filter) but not all years display
- CPT tags not showing when editing post
- Persist meta box choices throughout all posts of same post type
- Assign for all post of a post type a specific single-post template
- Display custom tax in “while” loop
- Custom post type archive false is not compatible with breadcrumbs
- Overriding a CPT template file through functions.php
- help me to display featured image of specific post by post id
- How do I retrieve the title of a term of a custom post type with custom taxonomies?
- 404 custom post type
- Displaying WordPress Parent field in child post
- Custom post tag images not displaying with ACF
- Custom WordPress URL
- How to assign custom post template to its custom taxonomy terms
- Excluding top level from taxonomy and post loop
- Paginating custom query on category template
- Get a list of categories ids
- Custom Post Type Loop breaking php
- Styling first post using Advanced Custom Fields