カスタム投稿のアーカイブページ
<form method="get" id="storeSearch" action="<?php echo home_url('/'); ?>store/">
<input type="text" name="s" id="storeSearchInput" value="<?php the_search_query(); ?>" placeholder="キーワードを入力" />
<input type="hidden" name="post_type" value="store">
<input type="submit" value="検索する" />
</form>
function.php
add_filter('template_include','custom_search_template');
function custom_search_template($template){
if ( is_search() ){
$post_types = get_query_var('post_type');
foreach ( (array) $post_types as $post_type )
$templates[] = "search-{$post_type}.php";
$templates[] = 'search.php';
$template = get_query_template('search',$templates);
}
return $template;
}
意図している検索結果→https://www.gohandoki.com/store/?s=a&post_type=store
管理画面にログインしていない時の検索結果→https://www.gohandoki.com/?s=a
]]>Please help me!!! I have recently been brought in as web manager. I don’t yet have access to our WP sites, so I cant do much more exploration of the back end at the moment. But i’m trying to find a solution which I may bring up to my boss (director.)
]]>I was wondering if it is possible to include the shortcodes on a search results page, so that eg a tag cloud on top of the search results page shows all the tags that are used in the posts that match a specific query / search result.
I am not sure how I would go about including the shortcodes on the search results page.
Thank you for a great plugin
cheers,
Rob
Since I have to build a custom theme for a project, I could work around it then, but for the life of me I can’t get Relevanssi to work…
Best Martin
]]>I’m working on a website based on HTML5_blank theme and I encoutered issue on the search result page wich is not scrolling at the bottom of the website. I can’t see the footer and have no idea why.
There’s no error or warning on console so it not seems to be a JS error. I suspected an HTML / PHP structure but if I basically replace all the content by another one the scroll issue is still here so I’m a bit confused.
I already searched on the forum but I couldn’t find any topics related to my issue.
If anyone have already encountered this issue and know a solution ?
Here’s the URL : [ redundant link removed ]
More information :
– I don’t use any plugin related to scroll or infinit scrolling
– This is a WP_query loop setting to only search “post”
Thanks by advance,
Rapha?l.
I’m trying to build a version of the wordpress search results page.
I’ve tried to find a basic example of the loop I need to put on the page to display the results, but after Googling, I can’t find a straight forward answer.
What I’ve currently written clearly has errors in the code because it will only render 1 result on each paginated page. I want it to return 25 results per page from a specific category (165).
I’ve discovered that when I remove infinite scroll the paginated results are in fact only displaying 12 posts when there are actually 36 in category 165.
To compound the problem I am trying to use Metafizy’s Isotope filtering and Jquery infinite scroll to display my results, which is making my code hard to follow.
I think the problem is in the fact I’m using query_posts to display my results, but this new WP_Query I’ve written further down the page (see code).
All in all, I’m quite confused at this point. I’d really appreciate it if someone could provide me with the simple loop I need to add to search.php in my theme so it will render all 36 results from category 165 with the results being paginated with each paginated page displaying 25 posts.
Here is my current code.
<?php
/**
* The template for displaying Search Results pages.
*
* @package WordPress
* @subpackage pBone
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
get_header();
?>
<div id="wrapper" class="container d-sm-flex">
<div class="">
<?php query_posts( array('paged' => get_query_var('paged'), 'post_type' => array( 'post'), 's' => $s ) ); if ( have_posts() ): ?>
<h2>Search results for: <?php echo get_search_query(); ?></h2>
<div class="filters" id="collapseExample">
<div class="ui-group">
<p class="text-monospace m-0">Choose an instrument</p>
<div class="button-group js-radio-button-group d-flex flex-wrap" data-filter-group="instrument">
<button class="btn btn-primary button is-checked mr-1 mb-1" type="button" data-filter="">any</button>
<?php
$terms = get_terms( 'category', array('parent' => 165)); // get all categories, but you can use any taxonomy
$count = count($terms); //How many are they?
if ( $count > 0 ){ //If there are more than 0 terms
foreach ( $terms as $term ) { //for each term:
echo "<button class='button btn btn-primary mr-1 mb-1' type='button' data-filter='.".$term->slug."'>" . $term->name . "</button>\n";
//create a list item with the current term slug for sorting, and name for label
}
}
?>
</div>
</div>
<div class="ui-group">
<p class="text-monospace m-0">Pick your resource type</p>
<div class="button-group js-radio-button-group d-flex flex-wrap" data-filter-group="type">
<button class="button is-checked btn btn-primary mr-1 mb-1" type="button" data-filter="">any</button>
<?php
$field_key = "field_5ed77f279f5e2";
$field = get_field_object($field_key);
if( $field )
{
foreach( $field['choices'] as $k => $v )
{
echo '<button class="button btn btn-primary mr-1 mb-1" type="button" data-filter=".' . $k . '">' . $v . '</button>';
}
}
?>
</div>
</div>
</div>
<?php
$terms_ID_array = array();
foreach ($terms as $term)
{
$terms_ID_array[] = $term->term_id; // Add each term's ID to an array
}
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$terms_ID_string = implode(',', $terms_ID_array); // Create a string with all the IDs, separated by commas
//$the_query = new WP_Query( 'posts_per_page=3&cat='.$terms_ID_string ); // Display 50 posts that belong to the categories in the string
$the_query = new WP_Query ( array(
//'cat' => $terms_ID_string,
'posts_per_page' => 25,
'paged' => $paged
));
?>
<?php if ( $the_query->have_posts() ) : ?>
<div id="Grid" class="article-feed grid d-md-flex pt-4">
<?php while ( have_posts() ) : the_post();
$termsArray = get_the_terms( $post->ID, "category" ); //Get the terms for this particular item
$termsString = ""; //initialize the string that will contain the terms
foreach ( $termsArray as $term ) { // for each term
$termsString .= $term->slug.' '; //create a string that has all the slugs
}
?>
<?php
$colors = get_field('content-type');
if( $colors ):
?>
<?php foreach( $colors as $color ): ?>
<?php $color = strtolower($color); ?>
<?php $color = str_replace(' ', '-', $color); ?>
<div data-src="<?php echo $color; ?>" class="article infinite-item item <?php echo $termsString;?> <?php echo $color; ?> col-md-6 col-lg-4 mb-4 hidden-opacity">
<?php // 'item' is used as an identifier (see Setp 5, line 6) ?>
<div class="c-opus__box u-box-shadow card ">
<?php if ( has_post_thumbnail() ) : ?>
<div class="thumbnail">
<span>
<div class="isotope-im-wrapper col d-flex align-items-center justify-content-center p-0 pt-4 pt-md-0">
<?php
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) );
?>
<!-- Standard version -->
<img class="img-fluid card-img-top" src="<?php the_post_thumbnail_url(); ?>"/>
</div>
</span>
</div>
<?php endif; ?>
<div class="card-body ">
<h3 class="u-h4 c-opus__title u-margin-bottom-small card-title"><?php the_title(); ?></h3>
<div class="o-layout">
<?php $content = get_the_content(); echo mb_strimwidth($content, 0, 400, '...');?>
</div>
<?php if(get_field('hubspot_cta_embed_code')): ?>
<?php the_field('hubspot_cta_embed_code'); ?>
<?php endif; ?>
<?php if(get_field('keyword_tags')): ?>
<div class="keyword-tags">
<hr class="my-4">
<p class="lead"><strong>Tags</strong></p>
<?php the_field('keyword_tags'); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div><!-- end isotope-list -->
<?php else : ?>
</div><!-- end isotope-list -->
<?php endif; ?>
<?php endwhile; ?>
<!-- status elements -->
<div class="scroller-status" style="display: block;">
<div class="loader-ellips infinite-scroll-request" style="display: none;">
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
</div>
<p class="scroller-status__message infinite-scroll-last" style="display: block;">End of content</p>
<div class="scroller-status__message infinite-scroll-error" style="display: none;"><p>No results found</p></div>
</div>
<p class="pagination">
<?php previous_posts_link( 'Older posts' ); ?>
<?php next_posts_link( 'Newer posts' ); ?>
</p>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<h2>No search results for: <?php echo get_search_query(); ?></h2>
<?php endif; ?>
</div><!-- #wrapper -->
</div>
<?php else : ?>
No results found please use a different search term.
</div>
</div>
<?php endif; ?>
<?php get_footer(); ?>
]]>The search results are supposed to replace the blogfeed found in the gray box to the right of the screen, but are currently displaying a chopped up version in the gray box and yet are fully displayed in the blue section in the center of the screen. That center portion is reserved for whatever post the reader happens to be viewing, and the results should only display in the gray box, replacing the blog feed.
I have looked at the CSS, and there doesn’t seem to be any trouble there. I also have played around a bit with the function code, which seems to either make no difference or make it worse. I also have the Reading section of the site marked to display at least 10 posts. I am almost 100% certain I have made a rookie error in either the search.php file or the loop.php file, but I am not sure what it is. I am including both codes here, as well as the pagination.php file. Thanks for the help in advance.
Search
<?php get_header(); ?>
<div id="mySidenav" class="sidenav" style="background-image: url('gard.jpg')">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>
</div>
<div id="sidebar">
<div id="top">
<div id="menucontainer" cursor:"pointer" onclick="openNav()">
<p> Menu </p>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</div>
</div>
<div id="middle" style="background-image: url('gard.jpg')"></div>
<div id="bottom"></div>
</div>
<div id="center">
<header>
<!-- post title -->
<div id="excerptbox">
<?php theme1wp_excerpt('theme1wp_index'); ?>
</div>
<div id="borderboxtext">
<!-- post title -->
<div id="titletextbox">
<?php the_title(); ?>
<?php $subtitle = get_post_meta($post->ID, 'subtitle', true); if ($subtitle !== '') {echo '<p>' . $subtitle . '</p>';
} ?>
</div>
<!-- /post title -->
</div>
<!-- /post title -->
<!-- post thumbnail -->
<div id="headpic">
<?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(); // Fullsize image for the single post ?>
</a>
<?php endif; ?>
</div>
<!-- /post thumbnail -->
</header>
<div id="post">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<span id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- post details -->
<span class="date"><?php the_time('F j, Y'); ?></span>
<!-- /post details -->
<?php the_content(); // Dynamic Content ?>
<?php the_tags( __( 'Tags: ', 'theme1' ), ', ', '<br>'); // Separated by commas with a line break at the end ?>
</span>
<!-- /article -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h1><?php _e( 'Sorry, nothing to display.', 'theme1' ); ?></h1>
</article>
<!-- /article -->
<?php endif; ?>
</div>
<div id="comments">
<?php comments_template(); ?>
</div>
</div>
<footer>
<p class="copyright">
© 2016 - <?php echo date('Y'); ?> Copyright <?php bloginfo('name'); ?>.
</p>
<p>
This site is meant for entertainment purposes only and is not intended to replace professional knowledge.
</p>
</footer>
</div>
<div id="rightcontainer">
<button id="down" onclick="scrollDown()" onmouseenter="Highlight1()">▼</button>
<button id="up" onclick="scrollUp()" onmouseenter="Highlight2()">▲</button>
<h1><?php echo sprintf( __( '%s Search Results for ', 'theme1' ), $wp_query->found_posts ); echo get_search_query();?></h1>
<?php get_template_part('loop'); ?>
<?php get_template_part('pagination'); ?>
</div>
</div>
<?php get_footer(); ?>
Loop
<div id="blogcontainer" onmouseover="RollOff1()" onmouseout="RollOff2()">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<div id="postcontainer">
<!-- post thumbnail -->
<div class="thumb">
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(100,100)); // Declare pixel size you need inside the array ?>
</a>
<?php endif; ?>
</div><!-- /post thumbnail -->
<div class="topblock">
<div class="titleblock">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</div>
<div class="moreblock"> <a href="<?php the_permalink(); ?>">MORE ></a></div>
</div>
<div class="block">
<div class="date"><p><span class="date"><?php the_time('F j, Y'); ?></span></p></div>
<?php html5wp_excerpt('theme1wp_index'); // Build your custom callback length in functions.php ?>
</div>
<!-- /post details -->
</div>
<!-- /article -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<h2><?php _e( 'Sorry, nothing to display.', 'theme1' ); ?></h2>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
Pagination
<div class="pagination">
<?php theme1wp_pagination(); ?>
</div>'
This is the pagination function in the function.php file
function theme1wp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
}
]]>Anyone has an idea about why it acts like that ?
And what can i do to make it good ?
i tried things with search.php (which i can’t find, as such, in the customizr template contents), etc, but i don’t manage php…
my version is:
# SITE_URL: https://torpeurferveur.tf/cancot
# HOME_URL: https://torpeurferveur.tf/cancot
# IS MULTISITE : No
# THEME | VERSION : customizr | v4.1.25# WP VERSION : 5.0.3
# PERMALINK STRUCTURE : /%postname%/
# ACTIVE PLUGINS :
All-in-One WP Migration: 6.82
Gmedia Gallery: 1.14.4
Google Captcha (reCAPTCHA) by BestWebSoft: 1.39
Google Fonts for WordPress: 1.4.8
Grid Kit: 1.8.16
Nimble Page Builder: 1.4.2
Regenerate Thumbnails: 3.1.0
SecuPress Free — WordPress Security: 1.4.7
Testimonials Slider and Showcase: 1.2.4
WP SVG Icons: 3.2.1
Yoast SEO: 9.4
PHP Version: 7.2.13
MySQL Version: 5.5.5-10.1.37-MariaDB-1~jessie
Web Server Info: Apache/2.4.25 (Debian)
WordPress Memory Limit: 192MB
PHP Memory Limit: 192M
PHP Upload Max Size: 96M
PHP Post Max Size: 97M
PHP Upload Max Filesize: 96M
PHP Time Limit: 120
PHP Max Input Vars: 16384
PHP Arg Separator: &
PHP Allow URL File Open: No
WP_DEBUG: Disabled
Show On Front: page
Page On Front: (#0)
Page For Posts: (#0)
Thank you very much for your help !
]]>Search page code is as follows:
<?php get_header();
global $wp_query; ?>
<div style="background: #fff;" id="container">
<div style="background: #fff;" class="container">
<div class="row">
<div class="col-sm-12">
<?php if ( have_posts() ) { ?>
<div class="page-title">
<h1><?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>"</h1>
</div>
<?php while ( have_posts() ) { the_post();
$post_excerpt = substr(get_the_excerpt(), 0,240);
$post_excerpt = str_replace('Description', '', $post_excerpt);?>
<div class="row">
<?php if (has_post_thumbnail()):?>
<div class="col-sm-2">
<a>">
<?php the_post_thumbnail('medium') ?>
</a>
</div>
<div class="col-sm-10">
<h3><a>">
<?php the_title(); ?>
</a></h3>
<?php echo $post_excerpt .'...'; ?>
<div class="read-more">
<a>">Read More</a>
</div>
</div>
<?php else: ?>
<div class="col-sm-12">
<h2>
<a>">
<?php the_title(); ?>
</a>
</h2>
<?php echo $post_excerpt; ?>
<div class="read-more">
<a>">Read More</a>
</div>
</div>
<?php endif; ?>
</div>
<hr>
<?php } ?>
<?php paginate_links(); ?>
<?php } ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
]]>