0

its my page-ajax.php file


define('WP_USE_THEMES', false);
require_once('../../../wp-load.php');

   $terms = get_terms( 'bk-category' );
   foreach ( $terms as $term ) {
 }

$bkcat = $term->term_id;
     $args = array(
    'posts_per_page'   => -1,
    'category'         => $bkcat,
    'order'            => 'ASC',
    'post_type'        => 'bk-post',

    );
     $the_query = new WP_Query($args);
     if($the_query->have_posts()) {
            ?>

                     $i = 1;
                     while($the_query->have_posts()) : $the_query->the_post();
                     $a = $i++;

                      endwhile;
                     }



and this my page-table.php file


global $post;
  $terms = get_terms( 'bk-category' );
  $select = "n";
  $select.= "Select categoryn";

  foreach($terms as $term){
    if($term->count > 0){
        $select.= "slug."'>".$term->name."";
    }
  }

  $select.= "";

  echo $select;




$(document).ready(function() {
   var dropdown = document.getElementById("cat");
    function onCatChange() {
        if ( dropdown.options[dropdown.selectedIndex].value != -1 ) {
    $('.results').html("/images/loading.gif' />");
    $.ajax({
        type: 'POST',
        async: true,
        dataType   : "html",
        url: "/page-ajax.php",
        success: function (data){
            $('.results').html(data);
        }
    });
        }
    }
    dropdown.onchange = onCatChange;

});


In this case all shows or All Categories Shows , but : I just want to show only the contents of each category is clicked

1 Answer 1

1
//$bkcat = $term->term_id; try to call this via post from ajax where you will pass id of category
 $args = array(
'posts_per_page'   => -1,
'category'         => $bkcat,
'order'            => 'ASC',
'post_type'        => 'bk-post',
'category_name'    => $bkcat,

);
 $the_query = new WP_Query($args);
 if($the_query->have_posts()) {
        ?>

                 $i = 1;
                 while($the_query->have_posts()) : $the_query->the_post();
                 $a = $i++;

                  endwhile;
                 }

In case if you have query still let me know I will explain you entire code.

6
  • tnq my frind , but its not working for me :/ I just want to show only the contents of each category is selected please chek this url : yon.ir/2aO3
    – amirali bk
    Commented Jan 18, 2017 at 10:34
  • Please pass the id of the category in ajax and then you can fetch it into my page-ajax.php using $_POST mehtod Commented Jan 18, 2017 at 11:55
  • how? Please write code
    – amirali bk
    Commented Jan 18, 2017 at 13:22
  • hi Not somebody help me?
    – amirali bk
    Commented Jan 21, 2017 at 10:09
  • wait I am making code for you Commented Jan 23, 2017 at 4:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.