WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have question. I would like to load post content, custom post, depends on category. So first of all I would like to have drop down menu which will list all my categories then once user will select category list of post title will appear in second drop down (post from that particular category) then once that title selected post content will load. All that needs to be done on one page and without reloading so using Ajax. I stacked at the very beginning

<script type="text/javascript">
                    var $mainCat=$('#main_cat').val();

                    // call ajax
                                                        data:'action=my_special_action&main_catid=' + $mainCat,

                                //  alert(results);

And I found that bit which was inserted into function.php and I do realize that that needs to be modified somehow to pull out posts rather then children of categories

add_action('wp_ajax_my_special_action', 'my_action_callback');
add_action('wp_ajax_nopriv_my_special_action', 'my_action_callback');
function implement_ajax() {
            $categories=  get_term_by('child_of='.$_POST['main_catid'].'&hide_empty=0');
              foreach ($categories as $cat) {
                $option .= '<option value="'.$cat->term_id.'">';
                $option .= $cat->term_id;
                $option .= ' ('.$cat->category_count.')';
                $option .= '</option>';

              echo '<option value="-1" selected="selected">Scegli...</option>'.$option;
            } // end if
add_action('wp_ajax_my_special_ajax_call', 'implement_ajax');
add_action('wp_ajax_nopriv_my_special_ajax_call', 'implement_ajax');//for users that are not logged in.

Thats as far as i got. Any help will be appreciated

share|improve this question
did you write any php code? Also use full url to the admin-ajax.php – Sisir May 9 '12 at 20:24
yes i found code which could be used to pull the subcategories but that doesn't work either, see above – jmysona May 9 '12 at 22:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.