Basically I have newsletter.php page where all the existing custom post are display. from here, I have a dropdown category lists which you can filter the custom post by its category. once you click the specific category, it will proceed to pdf_cat.php to display the filtered output. the problem is the result page item doesn't show up. can you help me to figure it out the logic here? here are my code so far:
from newsletter.php --> dropdown category button:
<select name="form" id="form">
<div >
<option value="<?php echo home_url('/newsletter'); ?>" selected>一覧</option>
<?php
$args = array(
'orderby' => 'slug',
'order' => 'ASC',
'parent' => 0,
'hide_empty' => false
);
$terms = get_terms([
'taxonomy' => 'pdf_cat',
'hide_empty' => false,
]);
foreach( $terms as $term ){
echo '<option value="'. get_term_link($term->term_id) .' ">' . $term->name . '</option>';
}
?>
</div>
</select>
My JS to fire the url link:
<script type="text/javascript">
$("#form").change(function(){
var url = $(this).val();
location.assign(url);
});
</script>
My pdf_cat.php page where the filtered result supposed to display:
<?php
$terms = get_the_terms(); // get the category from query
$terms = $term[0];
$term_name = get_term_name($term->name); // get the category name
$term_id = get_term_ID($term->term_id); // get the catehory ID
?>
<?php
$paged = get_query_var('paged', 1);
$args = array( // asigned the functions inside the array
'paged' => $paged,
'post_type' => 'pdf',
'taxonomy' => $term_id,
);
$query = new WP_Query($args); // get the functions inside the assigned name
global $query_string; //Post the specify numbers per page
query_posts( $query_string . "&posts_per_page=12&paged=".$paged );
while ( have_posts() ) : the_post()
?>
Can anyone help me to fixed this issue? I hope this time I explain it clearly.
CodePudding user response:
You just need to change your pdf_cat.php to taxonomy.php and allow wordpress to open the taxonomy id link for you^^
check this link https://wphierarchy.com/