I want to filter my custom posts (pump) with a custom filter form on it's archive page (archive-pump.php).
So, I wrote the form markup:
<form method="GET">
<label>Series</label>
<?php
if( $terms = get_terms( array( 'taxonomy' => 'series', 'orderby' => 'name' ) ) ) :
echo '<select name="series">';
foreach ( $terms as $term ) :
echo '<option value="' . $term->term_id . '">' . $term->name . '</option>'; // ID of the category as the value of an option
endforeach;
echo '</select>';
endif;
?>
<button type="submit">Apply filter</button>
</form>
And I have this to output my custom posts:
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php the_title( '', '', true ); ?>
<?php endwhile; endif; ?>
When I open my page (localhost/project/pumps) it looks fine. But when I submit my form I'm getting an 404 page.
I maybe need an seperate query to fetch all the $_GET data. But I'm not getting to the step because of the 404 error.
What am I doing wrong? Thank you!
I want to filter my custom posts (pump) with a custom filter form on it's archive page (archive-pump.php).
So, I wrote the form markup:
<form method="GET">
<label>Series</label>
<?php
if( $terms = get_terms( array( 'taxonomy' => 'series', 'orderby' => 'name' ) ) ) :
echo '<select name="series">';
foreach ( $terms as $term ) :
echo '<option value="' . $term->term_id . '">' . $term->name . '</option>'; // ID of the category as the value of an option
endforeach;
echo '</select>';
endif;
?>
<button type="submit">Apply filter</button>
</form>
And I have this to output my custom posts:
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php the_title( '', '', true ); ?>
<?php endwhile; endif; ?>
When I open my page (localhost/project/pumps) it looks fine. But when I submit my form I'm getting an 404 page.
I maybe need an seperate query to fetch all the $_GET data. But I'm not getting to the step because of the 404 error.
What am I doing wrong? Thank you!
Share Improve this question asked Oct 10, 2020 at 0:54 TantaalTantaal 233 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1The problem is that you're using term IDs in your URL, but that is incorrect.
Use the term slug instead.
For example, lets say we have a mytax
term named helloworld
with the term ID 1:
example/cpt/?mytax=1
404example/cpt/?mytax=helloworld
a cpt archive filtered by thehelloworld
term
?tag=react
worked perfectly for me. – Tom J Nowell ♦ Commented Oct 10, 2020 at 17:21?tag=react
worked for me, but using thereact
terms ID did not. I'm assuming though that there is noquery_posts
call on this page? – Tom J Nowell ♦ Commented Oct 10, 2020 at 18:40