user3596108
user3596108

Reputation: 19

Wordpress not filtering posts

I'm making a Wordpress template on my own. On the top of the header, there is a fixed search input, so the user can search for any posts with a determinate tag whenever he wants to.

The problem is that when I type a tag keyword on the input, it always shows all the posts, not filtering any of it at all.

But when I search for a keyword that has no tag registered, it returns a 404.php error page.

One curious thing is that when there is a tag keyword, the link appears like this: /wordpress/tag/name-of-the-tag/

And when there is no tag with that keyword, it appears as: /wordpress/?tag=name-of-the-tag/

My form code is right below:

<form method="get" action="<?php echo esc_url( home_url( '/' ) );?>"> 

    <input id="s" type="text" name="tag" onfocus="if (this.value=='Buscar...') this.value = '';" onblur="if (this.value=='') this.value = 'Buscar...'" name="search" class="form-search" value="Buscar..."/>

</form>

Upvotes: 0

Views: 53

Answers (1)

vaso123
vaso123

Reputation: 12391

You've add the name attribute twice. With a value tag and search. Remove all of them and add a name="s"

This is from CODEX

<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url(home_url('/')); ?>">
    <div>
        <label class="screen-reader-text" for="s"><?php _x('Search for:', 'label'); ?></label>
        <input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="<?php echo esc_attr_x('Search', 'submit button'); ?>" />
    </div>
</form>

Upvotes: 0

Related Questions