admin管理员组文章数量:1122846
I am using the Easy Digital Downloads plugin to sell my music.
I would like to add a custom search form inside the downloads archive page so the results will be displayed on that page.
For example, if you'll go to storename/downloads and search for 'whatever', you'll find all the songs that contain 'whatever' in their title.
So, inside the archive-download.php file I added:
<div class="search-in-store">
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo home_url( '/downloads/' ); ?>">
<div>
<label class="screen-reader-text" for="find">Search for:</label>
<input type="text" value="" name="find" id="find" />
<input type="hidden" name="post_type" value="download" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
<?php
if ( isset( $_REQUEST[ 'find' ] ) ) {
// run search query
query_posts( array(
's' => $_REQUEST[ 'find' ],
'post_type' => $_REQUEST[ 'download' ],
'paged' => $paged
)
);
// loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
// loop through results here
endwhile; endif;
// return to original query
wp_reset_query();
}
?>
</div>
but the problem is that when I'm searching for something, the url changed but the page displays the same content (it didn't filter anything).
/?find=love&post_type=download
I would like to url above to display ONLY the products with 'love' but it keeps showing all the products.
Any help will be much appreciated. Thank you
I am using the Easy Digital Downloads plugin to sell my music.
I would like to add a custom search form inside the downloads archive page so the results will be displayed on that page.
For example, if you'll go to storename.com/downloads and search for 'whatever', you'll find all the songs that contain 'whatever' in their title.
So, inside the archive-download.php file I added:
<div class="search-in-store">
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo home_url( '/downloads/' ); ?>">
<div>
<label class="screen-reader-text" for="find">Search for:</label>
<input type="text" value="" name="find" id="find" />
<input type="hidden" name="post_type" value="download" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
<?php
if ( isset( $_REQUEST[ 'find' ] ) ) {
// run search query
query_posts( array(
's' => $_REQUEST[ 'find' ],
'post_type' => $_REQUEST[ 'download' ],
'paged' => $paged
)
);
// loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
// loop through results here
endwhile; endif;
// return to original query
wp_reset_query();
}
?>
</div>
but the problem is that when I'm searching for something, the url changed but the page displays the same content (it didn't filter anything).
https://www.storename.com/downloads/?find=love&post_type=download
I would like to url above to display ONLY the products with 'love' but it keeps showing all the products.
Any help will be much appreciated. Thank you
Share Improve this question asked Nov 21, 2017 at 10:21 idomsktidomskt 111 silver badge3 bronze badges1 Answer
Reset to default 0I think you need to modify the code to display the content as of now you are not displaying anything in side loop.
<?php
if ( isset( $_REQUEST[ 'find' ] ) ) {
// run search query
query_posts( array(
's' => $_REQUEST[ 'find' ],
'post_type' => $_REQUEST[ 'download' ],
'paged' => $paged
)
);
// loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
//
?>
<a href="<?php the_permalink();?>"><?php the_title();?> </a>
<?php
endwhile; endif;
// return to original query
wp_reset_query();
}
?>
Please check if this helps you
本文标签: customizationCustom search to display results within same page
版权声明:本文标题:customization - Custom search to display results within same page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294897a1929455.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论