Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter cizko

    (@cizko)

    Hehehe… alright. I’m not about busting your a.. if you are not one of those – well – let’s just call them “semi”-pros which seem to float around here a lot, bugging real pros for solutions and then charging their customers for copy and pasting those.
    And I don’t think I will take you up on your offer – here in Germany our health care system is working pretty well. But thanks anyway. ??

    Thread Starter cizko

    (@cizko)

    Just add the following right above the line “// Add your options:”

    jQuery('#metakeyselect').find('option').remove();
    $metakeyselect.append('<option value="#NONE#">— Select —</option>');

    But seriously – google is your friend here. Consider yourself lucky that I am in a great mood today, since you can not expect other people to do all the work for you…

    Thread Starter cizko

    (@cizko)

    Oh Daffydd57 – you are killing me here. Please tell me you are not making your money with wordpress…. ??

    https://lmgtfy.com/?q=clearing+select+using+jquery

    Thread Starter cizko

    (@cizko)

    BTW: If I got my reading right, this is *not a bug* but intended behaviour as of WP 3.6

    Thread Starter cizko

    (@cizko)

    filtering the list or simply resetting it to no content at all can be easily done with jquery…

    Thread Starter cizko

    (@cizko)

    I found a solution to this – or more likely a workaround. Append this to your theme’s functions.php and adjust the section “Add your options” accordingly to fit your needs:

    /**
     * Programatically add custom fields.
     *
     * @see https://wordpress.stackexchange.com/questions/98269/programatically-add-options-to-add-new-custom-field-dropdown/
     */
    
    function wpse_98269_script() {
    
        if (isset($GLOBALS['post'])) {
    
            $post_type = get_post_type($GLOBALS['post']);
    
            if (post_type_supports($post_type, 'custom-fields')) {
    
                ?>
    
                    <script>
    
                        // Cache:
                        var $metakeyinput = jQuery('#metakeyinput'),
                            $metakeyselect = jQuery('#metakeyselect');
    
                        // Does the default input field exist and is it visible?
                        if ($metakeyinput.length && ( ! $metakeyinput.hasClass('hide-if-js'))) {
    
                            // Hide it:
                            $metakeyinput.addClass('hide-if-js'); // Using WP admin class.
    
                            // ... and create the select box:
                            $metakeyselect = jQuery('<select id="metakeyselect" name="metakeyselect">').appendTo('#newmetaleft');
    
                            // Add the default select value:
                            $metakeyselect.append('<option value="#NONE#">— Select —</option>');
    
                        }
    
                        // Add your options:
                        $metakeyselect.append("<option value='Your_option_1'>Your option 1</option>");
                        $metakeyselect.append("<option value='Your_option_2'>Your option 2</option>");
                        $metakeyselect.append("<option value='Your_option_3'>Your option 3</option>");
                        $metakeyselect.append("<option value='Your_option_4'>Your option 4</option>");
                        $metakeyselect.append("<option value='Your_option_5'>Your option 5</option>");
                        $metakeyselect.append("<option value='Your_option_6'>Your option 6</option>");
    
                    </script>
    
                <?php
    
            }
    
        }
    
    }
    
    add_action('admin_footer-post-new.php', 'wpse_98269_script');
    add_action('admin_footer-post.php', 'wpse_98269_script');
Viewing 6 replies - 1 through 6 (of 6 total)