[php] search wp
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- (CPT - autor)
- header.php
- ------------
- <form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
- <label for="s">Search for:</label>
- <input type="text" value="" name="s" id="s" />
- <input type="hidden" value="autor" name="post_type" id="post_type">
- <input type="submit" id="searchsubmit" value="Search" />
- </form>
- search.php
- ------------
- <?php
- /* Start the Loop */
- global $post;
- $post_type = get_query_var('post_type');
- $args = array(
- 's' => esc_html( get_search_query( false ) ),
- 'post_type' => $post_type,
- 'posts_per_page' => 2
- );
- $myposts = get_posts( $args );
- foreach ( $myposts as $post ) : setup_postdata( $post );
- get_template_part( 'template-parts/content', 'search' );
- endforeach;
- wp_reset_postdata();
- ?>
Editor
You can edit this paste and save as new: