$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - wordpress dependent dropdownlist using post type is not working|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - wordpress dependent dropdownlist using post type is not working

matteradmin10PV0评论

wordpress dependent drop down list using post type is not working in ajax.

I need a ddl value from another ddl in post type.

i have 2 post type department and doctors, when i select a department in drop down list i need the doctors in that department using ajax and not by refresh

ajax

$('#dpt').change(function () {
            var dpt = $(this).val();
            jQuery.ajax({
                type: 'post',
                data: {id: dpt},
                success: function (data) {   
//                    alert(data);
                    $('#response').text('dpt : ' + data);
                }
            });
        });

wordpress dependent drop down list using post type is not working in ajax.

I need a ddl value from another ddl in post type.

i have 2 post type department and doctors, when i select a department in drop down list i need the doctors in that department using ajax and not by refresh

ajax

$('#dpt').change(function () {
            var dpt = $(this).val();
            jQuery.ajax({
                type: 'post',
                data: {id: dpt},
                success: function (data) {   
//                    alert(data);
                    $('#response').text('dpt : ' + data);
                }
            });
        });
Share Improve this question edited Jan 31, 2019 at 9:41 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Jan 31, 2019 at 5:11 sanjaysanjay 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

PHP

Select Doctors 'doctors', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'dptmnt', 'value' => $dpt, 'compare' => 'LIKE' ), 'order' => 'ASC' ), ); $events = new WP_Query($args); while ($events->have_posts()): $events->the_post(); ?> ">

HTML

Select Department 'dpt', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' ); $events = new WP_Query($args); while ($events->have_posts()): $events->the_post(); ?> ">

AJX

$(function () { $("select[name='dp']").change(function () { var str = ""; $("select[name='dp'] option:selected").each(function () { str += $(this).text() + " "; }); jQuery.ajax({ type: "POST", data: $("form#a").serialize(), success: function (data) { // alert(data); // jQuery(".res").html(data); $('#doc').html(data); } }); var str = $("form").serialize(); // $(".res").text(str); }); });

This work for me

Post a comment

comment list (0)

  1. No comments so far