Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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">
$(function(){
            $('#main_cat').change(function(){
                    var $mainCat=$('#main_cat').val();

                    // call ajax
                     $("#sub_cat").empty();
                        $.ajax({
                            url:"/wp-admin/admin-ajax.php",
                            type:'POST',
                                                        data:'action=my_special_action&main_catid=' + $mainCat,

                             success:function(results)
                                 {
                                //  alert(results);
                $("#sub_cat").removeAttr("style");
                $("#sub_cat").append(results);
                                        }
                                   });
                          }
                                    );
});
</script>

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() {
if(isset($_POST['main_catid']))
            {
            $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;
            die();
            } // 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

 
discard

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

Browse other questions tagged or ask your own question.