Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Widget: Custom Post Type Post Listing Dropdown on Admin Side

Here is what I discovered and use, maybe it will help you:

function custom_posttype_dropdown($name, $selected)
{       
    $out = "";
    $posts = get_posts(
        array(
            'post_type'  => 'bctap_templates',
            'numberposts' => -1
        )
    );
    if($posts )
    {

        $out="<select name="".$name.'" ><option>Select a Template</option>';
        foreach( $posts as $p )
        {
            if ($p==$selected)
            {
                $selected = "selected = 'selected'";
            }
            else
            {
                $selected = "";
            }
            $out .= '<option value="' . $p->ID . '" '.$selected.'>' .$p->post_title  . '</option>';
        }
        $out .= '</select>';
    } 
    else
    {
        $out="<select name="".$name.'" value="x" ><option>Select a Option</option>';
        foreach( $posts as $p )
        {               
            $out .= '<option value="x" '.$selected.'>None Created Yet.</option>';
        }
        $out .= '</select>';
    }
    return $out;
}

//to call
echo custom_posttype_dropdown($name, $selected);

Related Posts:

  1. Get all posts from custom post type and insert in select input as metabox
  2. echo selected value from dropdown
  3. fetch meta fields inside a widget
  4. Update postmeta Parent when post_status child change
  5. Metabox not show in categories custom post type cmb2
  6. WordPress request fiter order by related post’s post_title
  7. Custom Widget WP_Query problem
  8. Hide a widget inside a div on specific type of post
  9. Update database from Quick Edit according to Checkbox state of Custom Post Type
  10. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  11. Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
  12. Dynamic Custom Fields
  13. Show Custom Post Type meta boxes only on Page Edit
  14. Filter widget outputs
  15. How to make custom taxonomy into drop down select in a custom metabox
  16. Create a Dropdown from Custom Post Type
  17. Custom filter function not working with Custom post type
  18. Set Custom Post Type in Widget Settings for use in Widget
  19. Importing Data from a Non-WordPress database, into WP
  20. Getting thumbnails of a custom posts featured images in a page-templates metabox
  21. Want to be able to sign up subscribers as authors
  22. dropdowboxes with pre-selected custom fields optios that filters the results according seach needs
  23. List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
  24. Remove Post Custom Meta Box
  25. Can’t publish custom post type – “You are not allowed to edit this post.”
  26. wp_dropdown_pages doesn’t work with post_type argument
  27. Custom fields for custom post type
  28. Show future events based on custom field AND order by date
  29. Meta Data for Custom Post Type not saving
  30. Using preg_replace to filter custom textarea
  31. Check if post with same meta value exists
  32. Filter date from post meta when date is in string format
  33. Get only used meta_values
  34. If Post Meta Equals Current Title Conditional Advanced Custom Fields
  35. the_post_thumbnail call removing li in code
  36. Is there a way to exclude posts based on meta_values?
  37. Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
  38. Archieve.php not loading for custom post type
  39. how to set a WP Plugin’s url
  40. Submitting Custom Post Types with custom fields from Front-end form
  41. create custom meta box with default value
  42. Get $post->ID from a URL
  43. Displaying a div from an assigned meta_value when on a page
  44. Why isn’t a list of posts from my custom post type displaying in this widget?
  45. Meta data (Tags and Categories) for Custom Posts not showing.
  46. Display different information of a custom post type
  47. Create Array from custom post type to display a slider
  48. Setting Post Title via Meta Data returns Auto-draft
  49. How to Echo Metadata Value in Currency Format
  50. Issue on Working with Metabox – Checkbox to enable Sale Items
  51. Filter posts by tax (dropdown) and meta value
  52. delete_post_meta() for whole CPT / multiple posts?
  53. How to get specific post meta by title or id
  54. Page Template Dropdown For Custom Post Types
  55. Publish and save specific postmeta to a filtered post_type
  56. Add “Select All” to custom taxonomy
  57. How to move a post to different post type with all meta data?
  58. Why do I have to press the “Update” button twice to save my meta box values?
  59. How can I display a drop-down select of Post Names
  60. how to show records that don’t have custom meta value
  61. WP API Response does not show my registered metadata
  62. Unable to display selected post title in frontend from metabox wp_dropdown_pages()
  63. How to detect that the save_post hook is calling the callback associated to the current edit post page only
  64. $post->post_meta not pulling any post in wordpress/php
  65. Values from meta-box not on $_POST
  66. How to get dropdown instance value in WordPress custom Widget
  67. WP_Query of custom post type sorted by meta_key has unexpected results
  68. Metabox multiple custom post select -> display selected items?
  69. Returning a custom content types with meta values
  70. Custom post type suddenly stoped working after WordPress 5 update
  71. Batch Extract Date from post title and put into ACF custom field
  72. copy images from custom field to another custom field
  73. How to show custom field on specific custom post type posts only when filled
  74. How to handle this specific case of custom post type?
  75. Save CTP post meta different values each day without overwriting previous values
  76. get_post_meta returns NULL in front-end, but correct result in back-end
  77. Post Query not working
  78. Methods for development wordpress themes [closed]
  79. Cannot obtain custom meta information
  80. Problem with adding custom post type meta to header by plugin
  81. is_main_query() never called on WP 4.4
  82. Add search to ‘Parent’ dropdown
  83. How can I output WPAlchemy repeating fields meta values in my page template?
  84. Meta box data is saved but NOT displayed in the meta box text field. Why?
  85. How to call a post’s metadata in shortcode.php?
  86. display custom post type in widget aera
  87. Save Metabox Custom Field Value
  88. Echo custom post meta from options array
  89. Value of post meta dropdown is not showing in WordPress
  90. Meta box data not saving
  91. Get all metadata for a given custom post type
  92. Set Default Option Value as Blank for Meta Box
  93. WP_Meta_Query object with conditionals
  94. Trying to write shortcode with get_post_meta but isn’t working
  95. How to selected value default in option list?
  96. Display Taxonomy Term Children in a Drop Down without Submit Button
  97. Related posts meta_query CPT
  98. Meta box with front-end styling
  99. Sanitaizing Select Optin For Custom Post Type Metabox in WP
  100. How can I get some of a posts meta data whilst it is still inserting?
Categories custom-post-types Tags custom-post-types, dropdown, post-meta, select, widgets
Where should I hook into admin?
Query post for ‘selected category’ in archive.php

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress