Wordpress custom post template page/2 loop not working - wordpress

I have a loop in the sidebar of a custom template and it works perfectly when the page is loaded. The page is -
http://ere.doneready.com/senior-consultants
However the loop (which shows the list of names) does not work when I click the "next" button i.e. this page -
http://ere.doneready.com/senior-consultants/page/2/
Can anyone help? The following is the code I use -
<div id="people-sidebar-content">
<div id="custom-search-form-for-people">
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div id="custom-search-form-label"><label for="s" class="assistive-text"><?php _e( 'SEARCH' ); ?></label></div>
<span id="search-box-box"><input class="search-box" type="text" name="s" id="s" /></span>
<span id="search-box-button"><input type="image" name="submit" id="searchsubmit" SRC="http://www.doneready.com/ere/wp-content/themes/ere/images/search_button.png" HEIGHT="17" WIDTH="20" BORDER="0" ALT="Submit Form"></span>
</form>
</div>
<div id="people-sidebar-content-usable" class="senior-consultants-active">
<div id="sidebar-for-people">
<a class="directors" href="http:/www.ere.doneready.com/directors/">Directors</a><br />
<a class="finance-admin" href="http:/www.ere.doneready.com/finance-and-admin/">Finance & Admin</a><br />
<a class="senior-consultants" href="http:/www.ere.doneready.com/senior-consultants/">Senior Consultants</a><br />
<div id="actual-people-list">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
'post_type'=>'staff',
'posts_per_page' => 99,
'paged'=>$paged,
'staff_categories'=>'Senior Consultants'
);
$temp1 = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="actual-people-list-single">
<a href ="<?php the_permalink(); ?>">
<?php echo esc_html( get_post_meta( get_the_ID(), 'staff_short_name', true ) ); ?>
</a>
</div>
<?php
endwhile; endif;
/* PageNavi at Bottom */
$wp_query = null;
$wp_query = $temp1;
wp_reset_query();
?>
</div>
<a class="consultants" href="http:/www.ere.doneready.com/consultants/">Consultants</a><br />
<a class="technical-support" href="http:/www.ere.doneready.com/technical-support/">Technical Support</a>
</div>
</div><!--END PEOPLE-SIDEBAR-CONTENT-USABLE-->
</div><!--END PEOPLE-SIDEBAR-CONTENT-->
</div><!--END CONTENT CONTAINER-->
</div><!--END PAGE-WRAP-->

Welcome to StackOverflow, try to search the archives at least semi-extensively first because many variations of this question exist. Here's a link to my answer to a very similar question, it worked for me, it might work for you:
Making a single page blog in WordPress

Solved. I used a new loop and the code looks like this now -
<div id="people-sidebar-content">
<div id="custom-search-form-for-people">
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div id="custom-search-form-label"><label for="s" class="assistive-text"><?php _e( 'SEARCH' ); ?></label></div>
<span id="search-box-box"><input class="search-box" type="text" name="s" id="s" /></span>
<span id="search-box-button"><input type="image" name="submit" id="searchsubmit" SRC="http://www.doneready.com/ere/wp-content/themes/ere/images/search_button.png" HEIGHT="17" WIDTH="20" BORDER="0" ALT="Submit Form"></span>
</form>
</div>
<div id="people-sidebar-content-usable" class="senior-consultants-active">
<div id="sidebar-for-people">
<a class="directors" href="http:/www.ere.com.my/directors/">Directors</a><br />
<a class="senior-consultants" href="http:/www.ere.com.my/senior-consultants/">Senior Consultants</a><br />
<div id="actual-people-list">
<?php
$args = array( 'post_type' => 'staff', 'staff_categories'=>'Senior Consultants', 'posts_per_page' => 50 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="actual-people-list-single">
<a href ="<?php the_permalink(); ?>">
<?php echo esc_html( get_post_meta( get_the_ID(), 'staff_short_name', true ) ); ?>
</a>
</div>
<?php
endwhile;
?>
<?php
wp_reset_query();
?>
</div>
<a class="consultants" href="http:/www.ere.com.my/consultants/">Consultants</a><br />
<a class="technical-support" href="http:/www.ere.com.my/technical-support/">Technical Support</a>
<a class="finance-admin" href="http:/www.ere.com.my/finance-and-admin/">Finance & Admin</a><br />
</div>

Related

List custom taxonomies by custom field

Below I have my custom taxonomy template and its working fine until now.
<?php
/*
Template Name: Performer List Page
*/
get_header(); ?>
<?php
// if show all is set
$sortby=$_GET['sortby'];
if( isset($_GET['showall']) || isset($sortby) ):
$args = array( 'hide_empty' => 0 );
else:
// else show paged
$page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
global $framework_opt,$post; $number_of_performers = $framework_opt['performers_per_page'];
$orderby = 'date';
$order = isset( $_REQUEST['order'] ) ? trim( $_REQUEST['order'] ) : null;
if(isset($_GET['order']) && !empty($_GET['order'])) {
switch($order)
{
case 'alphabetically' : $orderby = 'title';
break;
case 'popularity' : $orderby = 'count';
break;
/*
case 'female' : $meta = 'gazi_female';
break;
case 'male' : $meta = 'gazi_male';
break;
*/
default : $orderby = 'date';
break;
}
}
// number of tags to show per-page
$per_page = $number_of_performers ;
$offset = ( $page-1 ) * $per_page;
$args = array( 'orderby' => $orderby, 'number' => $per_page, 'meta_key' => $meta, 'offset' => $offset, 'hide_empty' => 0 );
endif;
$taxonomy = 'performer';
$count_performers = wp_count_terms( $taxonomy, $offset );
$tax_terms = get_terms( $taxonomy, $args );
?>
<aside class="sidebar pull-left">
<p class="sidebar-title"><?php _e( 'SEARCH BY LETTER', 'gazi' ); ?></p>
<div class="letter-search clearfix">
<span class="letter">A</span>
<span class="letter">B</span>
<span class="letter">C</span>
<span class="letter" style="width:40%"><?php _e( 'All', 'gazi' ); ?></span>
<span class="letter" style="width:40%"><?php _e( 'Reset', 'gazi' ); ?></span>
</div>
<!--<p class="sidebar-title"><?php _e( 'QUICK SEARCH', 'gazi' ); ?></p>
<form class="frm-search-tag has-title" action="<?php echo home_url( '/' ); ?>" method="get">
<input type="text" placeholder="Search name" name="s" value="" />
<button type="submit"><span class="ico ico-search"></span>
<select class="search_tools" style="display:none;" name="taxonomy" >
<option value="performer">Videos</option>
<option value="gallery">Photos</option>
</select>
</button>
</form>-->
<div style="height: 5px;"></div>
<?php get_template_part( 'templates/sidebars/performer-sidebar', get_post_format() ); ?>
</aside>
<section class="main-section pull-left">
<div class="page-title with-sorter clearfix">
<h1><?php the_title(); ?></h1>
<div class="info hidden-mobile">
<p>
<?php echo $count_performers; ?><?php _e( 'Performers', 'gazi' ); ?> <span class="ico ico-tv"></span>
</p>
<div class="sorter">
<div class="dropdown-container">
<ul class="flyout-menu flyout-menu-right">
<li>
<button class="dropdown-toggle" type="button" data-action="dropdown-toggle" data-target="#sorter-dropdown">SORT</button>
<div class="flyout-menu-content" id="sorter-dropdown">
<ul class="flyout-menu-items">
<li>
<?php _e( 'Alphabetically', 'gazi' ); ?> </li>
<li>
<?php _e( 'Popularity', 'gazi' ); ?> </li>
</ul>
</div>
</li>
</ul>
</div></div> </div>
<div class="info visible-mobile clearfix">
<button class="btn-pd btn-pd-primary pull-left" style="margin-right: 0;" data-action="scroll-to" data-target="#letter-search">A-Z</button>
<p style="float:right">
<?php echo $wp_query->found_posts; ?> <?php _e( 'Performers', 'gazi' ); ?> <span class="ico ico-tv"></span></p>
</div></div>
<div id="performer-list" class="list-view">
<div id="performer-thumbs" class="performer-listing clearfix">
<div class="items">
<?php foreach ($tax_terms as $cat) : ?>
<?php
$flag = 0;
if( $sortby == substr( $cat->name, 0, 1 ) || $sortby=='' ) { $flag = 1;}
if ($flag=='1'){
?>
<article class="performer-item">
<a class="outline" href="<?php echo get_term_link($cat->slug, 'performer'); ?>" title="<?php echo $cat->name; ?>">
<?php $performer_image = z_taxonomy_image_url($cat->term_id); if(!empty($performer_image)) : ?>
<img src="<?php bloginfo('template_directory'); ?>/gazi/css/images/1pixel.gif" data-src="<?php echo z_taxonomy_image_url($cat->term_id,NULL, array(180, 240)); ?>" alt="<?php echo $cat->name; ?>" />
<noscript><img src="<?php echo z_taxonomy_image_url($cat->term_id,NULL, array(180, 240)); ?>" alt="<?php echo $cat->name; ?>" /></noscript>
<?php else : ?>
<img src="<?php bloginfo('template_directory'); ?>/gazi/css/images/1pixel.gif" data-src="<?php bloginfo('template_directory'); ?>/gazi/css/images/no-img-women.jpg" alt="<?php echo $cat->name; ?>" />
<noscript><img src="<?php bloginfo('template_directory'); ?>/gazi/css/images/no-img-women.jpg" alt="<?php echo $cat->name; ?>" /></noscript>
<?php endif; ?>
<span class="performer-name"><?php echo $cat->name; ?></span>
<span class="performer-videos hidden-mobile">
<span class="count"><?php echo $cat->count; ?></span>
<span class="txt"><?php _e( 'VIDEOS', 'gazi' ); ?></span>
</span>
</a>
<div class="performer-item-footer visible-mobile">
<span class="ico ico-take"></span> <?php echo $cat->count; ?> <?php _e( 'VIDEOS', 'gazi' ); ?> </div>
</article>
<?php } ?>
<?php endforeach; ?>
</div>
</div>
<?php
if( isset($_GET['showall']) || isset($sortby)):
echo '';
else:
// showall is set, show link to get back to paged mode
$total_terms = wp_count_terms( 'performer' );
$pages = ceil($total_terms/$per_page);
// if there's more than one page
if( $pages > 1 ):
echo '<div class="pager"><div class="paginator" id="performer_paginator">';
for ($pagecount=1; $pagecount <= $pages; $pagecount++):
echo '<a class="page" href="'.get_permalink().'page/'.$pagecount.'/"><span>'.$pagecount.'</span></a>';
endfor;
// link to show all
echo '<a class="page" href="'.get_permalink().'?showall=true">ALL</a>';
echo '</div>';
endif;
endif;
?>
</div>
<div id="letter-search" class="visible-mobile">
<div class="section-title with-sorter clearfix" style="margin-bottom: 4px;">
<p class="title">Letters Search</p>
<div class="info">
<button class="btn-pd btn-pd-sm btn-pd-primary pull-right" data-action="scroll-to" data-target="#performer-thumbs"><span class="ico ico-grid"></span></button>
</div>
</div>
<div class="letter-search clearfix">
<span class="letter">A</span>
<span class="letter">B</span>
<span class="letter">C</span>
</div>
</div>
<?php get_template_part( 'templates/advertisements_bottom', get_post_format() ); ?>
</section>
<?php get_footer(); ?>
If you see I added an order menu for popularity and videos count for this listing is working but under the order code you will see:
/*
case 'female' : $meta = 'gazi_female';
break;
case 'male' : $meta = 'gazi_male';
break;
*/
so I want to separate performers by male and female using the custom fields above.Any one that has any idea how to complete this template?
thanks
You want to show results based on meta field 'gazi_female' or 'gazi_male' so you should include in your meta_query arguments.
Instead of 'meta_key' => $meta use meta_query. Meta query in get_terms feature got introduced from 4.4.0 version, so make sure your version supports it with get_terms()
You should not use it in order_by parameter since order_by will sort the results and it cant filter results.
Alternatively try WP_Term_Query which is available from 4.6 versions
// WP_Term_Query arguments
$args = array (
'taxonomy' => array( 'performer' ),
'meta_key' => 'male',
'meta_value' => 'gazi_male',
);
// The Term Query
$term_query = new WP_Term_Query( $args );
// The Loop
if ( ! empty( $term_query ) && ! is_wp_error( $term_query ) ) {
// do something
} else {
// no terms found
}

Trying to apply same count to each item within a loop

I'm creating a loop in WordPress for a fancybox gallery. This means that each group of images needs to have the same rel identifier (for example rel="gallery1"). But since this is a nested loop, in other words, it's part of another loop, I need the next group of images in the loop to have a rel identifier different from the ones before/after (ex. rel="gallery2", rel="gallery3", etc.).
I've tried putting next the the word gallery, but it just loops and gives every object another number instead of keeping the same number for each item in the grouping.
I'm not sure if what I'm explaining is making sense. Here's a basic idea of what I'm trying to have.
{gallery of images 1}
<a href="image" rel="gallery1">
<img src="path">
</a>
<a href="image" rel="gallery1">
<img src="path">
</a>
<a href="image" rel=gallery1">
<img src="path">
</a>
{gallery of images2 }
<a href="image" rel="gallery2">
<img src="path">
</a>
<a href="image rel="gallery2">
<img src="path">
</a>
etc., etc.
The page itself is displaying a gallery of post thumbnails (featured images) from a custom post type. Clicking on a gallery item (representing one item in the custom post type) opens a Bootstrap modal window. In that modal window is a group of images related to that original gallery item (post type item). Clicking on one of those images opens a fancybox, but should only cycle through the images for that gallery item. Crazy enough?
The rest of the page is working perfectly. Just having trouble with this rel numbering thing.
I had hesitated posting all the code because it's so long, but if it's helpful, here you go:
// Define the query
$args = array(
'post_type' => 'pixieportfolio',
'post_status' => 'publish',
'orderby' => 'menu_order',
'meta_query' => array(
array(
'key' => 'featured_portfolio_item',
'value' => '1',
'compare' => '=',
)
),
'meta_key' => '_thumbnail_id',
'posts_per_page' => 999
);
$query = new WP_Query( $args );
$count = 0;
// Carousel // ?>
<div id="featuredCarousel" class="carousel slide" data-ride="carousel" data-pause="hover">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php while($query->have_posts()): $query->the_post(); ?>
<li <?php if($count == 0){ echo 'class="active"';} ?> data-target="#featuredCarousel" data-slide-to="<?php echo $count++; ?>"></li>
<?php endwhile; ?>
</ol>
<div class="carousel-inner" role="listbox">
<?php $count = 0;
while ($query->have_posts()) : $query->the_post();
$count++;
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'pp-home-portfolio' );
$url = $thumb['0'];
$values = get_field('tech_choices');
$terms = get_the_terms($post->ID, 'post_tag');
$custom = get_post_custom($post->ID);
$caption = get_field('caption', '');
$client = get_field('client', '');
$project_url = get_field('project_url', '');
$date = get_field('date', ''); ?>
<!-- Wrapper for slides -->
<div class="item <?php if ($count == 1) { echo 'active';} ?>" data-slide-number="<?php echo $count++; ?>" id="<? the_ID(); ?>">
<div class="item-image" style="background-image: url(<?=$url?>);" title="<?php the_title() ?>" data-toggle="modal" data-target="#myModal<?php echo $count; ?>"></div>
<div class="project-details">
<div class="project-detail-border shadow-effect"></div>
<div class="project-detail">
<div class="top-detail">
<h4><?php the_title(); ?></h4>
<div class="short-description">
<?php $content = get_the_content();
echo wp_trim_words( $content , '20' );
?>
</div>
</div>
<table class="table project">
<tr>
<td valign="middle" class="fifty">
<?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'pixie-portfolio-categories', '', ', ', '' ) );
echo $terms_as_text;?>
</td>
<td valign="middle" class="fifty">
<?php if( $values ) {
if(in_array('WordPress', $values )){ ?>
<i class="fa fa-wordpress fa-2x" data-toggle="tooltip" title="Wordpress"></i>
<?php } if(in_array('HTML-5', $values )){ ?>
<i class="fa fa-html5 fa-2x" data-toggle="tooltip" title="HTML-5"></i>
<?php } if(in_array('CSS-3', $values )){ ?>
<i class="fa fa-css3 fa-2x" data-toggle="tooltip" title="CSS-3"></i>
<?php } if(in_array('Sportswear', $values )){ ?>
<i class="fa fa-bicycle fa-2x" data-toggle="tooltip" title="Sportswear"></i>
<?php } if(in_array('Adobe', $values )){ ?>
<i class="fa fa-paint-brush fa-2x" data-toggle="tooltip" title="Adobe"></i>
<?php } if(in_array('Code', $values )){ ?>
<i class="fa fa-code fa-2x" data-toggle="tooltip" title="Code"></i>
<?php } if(in_array('Ecommerce', $values )) { ?>
<i class="fa fa-database fa-2x" data-toggle="tooltip" title="MySQL"></i>
<?php }
} else {} ?>
</td>
</tr>
<tr>
<td colspan="2" class="more-info" data-toggle="modal" data-target="#myModal<?php echo $count; ?>">
<div class="view-project">View Project</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<!-- Modal -->
<div id="myModal<?php echo $count; ?>" class="modal fade" role="dialog" aria-labelledby="myModal<?php echo $count; ?>Label">
<div class="modal-dialog modal-lg" role="document">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title"><?php the_title() ?></h2>
<span>
<?php if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<li><?php echo $term->name; ?></li>
<?php $icon = get_field('creative_icon', $term->taxonomy . '_' . $term->term_id); echo $icon; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</span>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-md-8">
<div>
<p class="post-meta gallery-list">
<?php if( $client ): ?>
<span class="pixie-date">
<span class="title">Client:</span> <?=$client?>
</span>
<?php endif;
if ( $date ): ?>
<span class="post-cats">
<span class="title">Date:</span> <?=$date?>
</span>
<?php endif;
if ( $values ) { ?>
<span class="post-comments">
<?php $values = get_field('tech_choices'); ?>
<span class="title">Tech used in this project:</span>
<?php if(in_array('WordPress', $values )){ ?>
<i class="fa fa-wordpress fa-2x" data-toggle="tooltip" data-placement="bottom" title="WordPress"></i>
<? }
if(in_array('HTML-5', $values )){ ?>
<i class="fa fa-html5 fa-2x" data-toggle="tooltip" data-placement="bottom" title="HTML5"></i>
<? }
if(in_array('CSS-3', $values )){ ?>
<i class="fa fa-css3 fa-2x" data-toggle="tooltip" data-placement="bottom" title="CSS3"></i>
<? }
if(in_array('Sportswear', $values )){ ?>
<i class="fa fa-bicycle fa-2x" data-toggle="tooltip" data-placement="bottom" title="Sportswear"></i>
<? }
if(in_array('Adobe', $values )){ ?>
<i class="fa fa-paint-brush fa-2x" data-toggle="tooltip" data-placement="bottom" title="Illustrator and/or Photoshop"></i>
<? }
if(in_array('Code', $values )){ ?>
<i class="fa fa-code fa-2x" data-toggle="tooltip" data-placement="bottom" title="PHP, JQuery, etc."></i>
<? }
if(in_array('Ecommerce', $values )){ ?>
<i class="fa fa-shopping-cart fa-2x" data-toggle="tooltip" data-placement="bottom" title="ECommerce"></i>
<? }
if(in_array('MySQL', $values )){ ?>
<i class="fa fa-database fa-2x" data-toggle="tooltip" data-placement="bottom" title="MySQL"></i>
<? } ?>
</span>
<?php } ?>
</p>
</div>
<?php echo the_content(); ?>
<blockquote class="testimonial">
QUOTE GOES HERE
</blockquote>
</div>
<div class="col-md-4">
<div class="gallery">
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'darwin-modal-main' );
$url = $thumb['0'];
$thumb2 = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );
$url2 = $thumb2['0'];
$c = 0; ?>
<a href="<?=$url2?>" class="group" id="port_gal" rel="group<?php echo $c; ?>">
<img src="<?=$url?>" width="300" height="300">
</a>
<?php $images = get_field('gallery_images');
if( $images ) {
foreach( $images as $image ) {
?>
<a href="<?php echo $image['sizes']['large'] ?>" class="group" id="port_gal" rel="group<?php echo $c; ?>">
<img src="<?php echo $image['sizes']['darwin-modal-thumb'] ?>" alt="<?php $image['alt'] ?>" />
</a>
<?php }
} ?>
</div>
<div class="website-button">
<?php if ( $project_url ): ?>
<a class="btn btn-default" href="<?=$project_url?>" target="_blank" role="button">Visit Website</a>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_query(); ?>
</div>

Search pagination wordpress

i have a problem with search result page, the pagination doesn't works, when i want to go to next page, i'm redirected to index page, but the url is: www.mywebsite.com/page/2/?s=word..
For all pages the pagination works, only for search doesn't works.
this is the code of search.php
<?php
/**
* The template for displaying Search Results pages.
*/
get_header(); ?>
<?php
$search = isset( $_GET['s'] ) ? $_GET['s']: null;
$user_filtre = '';
$user_display = '';
if( $search ){
$user_filtre .= 's=' . $_GET['s'] . '&';
$user_display .= 's=' . $_GET['s'] . '&';
}?>
<div id="main-search" class="content-dark hidden-sm hidden-xs">
<div class="container">
<form method="get" action="<?php bloginfo('url'); ?>" accept-charset="UTF-8">
<!--input name="s" id="s" type="hidden" -->
<div id="main-search-fields">
<p class="pull-left term">Search Term:</p>
<input name="s" value="<?php the_search_query(); ?>"autocomplete="off" type="search">
</div>
<div id="main-search-btn">
<input class="button-green-download-big" type="submit" value="Search">
</div>
</form>
</div>
</div>
<div class="browse-content">
<div class="container">
<section>
<div class="row">
<ul>
<?php if(have_posts() ): ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php include '_includes/items/item_2.php';?>
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
</section>
<?php novavideo_theme_pagination(); ?>
</div>
</div>
</div>
Anyone have an ideea?
item_2.php.
<div class="browse-movie-wrap col-xs-10 col-sm-4 col-md-5 col-lg-4">
<a href="<?php the_permalink(); ?>" class="browse-movie-link">
<figure>
<?php if($values = get_post_custom_values("poster_url")) { ?>
<img class="img-responsive" src="<?php echo $values[0]; ?>" alt="<?php the_title();?> Watch Online" width="210" height="315">
<?php } ?>
<figcaption class="hidden-xs hidden-sm">
<span class="fa fa-star icon-color"></span>
<h4 class="rating"><?php $rating = get_post_custom_values("imdbRating"); echo $rating[0]; ?> / 10</h4>
<h4>
<?php $categories = get_the_category();
if ( ! empty( $categories[0] ) ) {
echo esc_html( $categories[0]->name );
}
?>
</h4>
<h4 class="quality-button"><span class="fa fa-play-circle"></span> <?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'quality', '', ', ', '' ) ); echo $terms_as_text;; ?></h4>
<span class="button-green-download-big margin-button">Open Movie</span>
</figcaption>
</figure>
</a>
<div class="browse-movie-bottom">
<?php $title = get_post_custom_values("Title"); echo $title[0]; ?>
<div class="browse-movie-year"><?php $terms = wp_get_post_terms($post->ID, 'release-year', array("fields" => "all")); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ foreach ( $terms as $term_single ) { $term_link = get_term_link( $term_single ); echo $term_single->name; } } ?></div>
</div>
</div>
Search results are instantiated through query_posts and that controls how many results you have per page. In your code, it's probably happening via the include: /_includes/search-template.php but if not, set it up like this:
// 1- Created a paged variable that knows how many paginated pages exist (depends on your site)
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
// 2- Pass `paged` into array of arguments for query_posts
$args = array(
'posts_per_page' => 20,
'order' => 'DESC',
'paged' => $paged,
);
// 3- Submit query_posts to WordPress with arguments set
query_posts( $args );
Now you can use next_posts_link(); to show the paginated page link. Just replace the references to theme_pagination(); with next_post_link(); and it should output the right results.
If you want to abstract all this logic out of your template, check out pre_get_posts. It's a different method and you would put all this logic into functions.php but will achieve similar results.
This is my code for Search result page with pagination:
<?php get_header(); ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/search.css">
<?php wp_head(); ?>
<script type="text/javascript">
var window_width = window.screen.width;
var window_height = window.screen.height;
<?php $window_width = "<script>document.write(window_width)</script>";
$window_height = "<script>document.write(window_height)</script>"; ?>
</script>
<style>
.sm_bd{padding: 5px;
border: 1px solid
#ccc;}
.row {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
}
.row > [class*='col-'] {
display: flex;
flex-direction: column;
}
.previous,.next {
padding: 5px;
border: 1px solid
#ccc;
border-radius: 4px;
margin: 15px;
}
</style>
</head>
<body class="index-body">
<?php include 'menu.php';?>
<div class="col-xs-12 col-sm-12 blog-page no-marg no-padd">
<div class="col-xs-4 col-sm-3 single-sidebar no-marg no-padd">
My sidebar
</div>
<section id="primary" class="content-area col-xs-12 col-sm-12 col-lg-8 col-md-8">
<div id="content" class="site-content row" role="main">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : '1';
$s=get_search_query();
$args = array(
's' =>$s,
'paged' => $paged,
'posts_per_page' => '12',
);
// The Query
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
_e("<h2 style='font-weight:bold;color:#000'>نتایج جستجو برای: ".get_query_var('s')."</h2>");
echo "<div class='col-lg-12 col-md-12'><hr/></div>";
while ( $the_query->have_posts() ) {
$the_query->the_post();
?>
<div class="col-xs-12 col-sm-12 col-lg-3 col-md-3 sm_bd">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php else : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<img class="attachment-post-thumbnail size-post-thumbnail wp-post-image lazyloaded" src="Without Image"
alt="<?php the_title_attribute(); ?>"
title="<?php the_title_attribute(); ?>" width="300" height="449">
</a>
<?php endif;?>
<?php the_title(); ?>
</div>
<?php
}
?>
<div class="pagination" id="blog-pagination">
<?php if( get_previous_posts_link('← ', $loop->max_num_pages ) ) : ?>
<span class="previous" ><?php previous_posts_link( '→ ', $loop->max_num_pages ); ?></span>
<?php endif; ?>
<?php if( get_next_posts_link('← ', $loop->max_num_pages ) ) : ?>
<span class="next"><?php next_posts_link( '←', $loop->max_num_pages ); ?></span>
<?php endif; ?>
</div>
<?php
}
else{
?>
<h2 style='font-weight:bold;color:#000'>not found title</h2>
<div class="alert alert-info">
<p>not found alert</p>
</div>
<?php }
wp_reset_postdata();?>
</div><!-- #content .site-content -->
</section><!-- #primary .content-area -->
</div>
<?php get_footer(); ?>
don't forget to write wp_reset_postdata(); after post loop.

Search Form not working on Wordpress

I am having problems with the search form on wordpress. When i try and search any term at all it gives me the "Sorry, no posts match your query" response (I have "Search Everything" plugin installed too). I am using a child theme. so I tried to change the code in the child search.php (copied it to the child) and also created a searchform.php in the child. Here is the code from both of those that I am currently using:
SEARCH.PHP:
> <?php
/**
* Search Template
*
* The search template is used to display search results from the native WordPress search.
*
* If no search results are found, the user is assisted in refining their search query in
* an attempt to produce an appropriate search results set for the user's search query.
*
* #package WooFramework
* #subpackage Template
*/
get_header();
global $woo_options;
?>
<!-- #content Starts -->
<?php woo_content_before(); ?>
<div id="content" class="col-full">
<div id="main-sidebar-container">
<!-- #main Starts -->
<?php woo_main_before(); ?>
<section id="main" class="col-left">
<header class="page-header">
<h1 class="page-title"><?php printf( __( 'Search Results for: %s', '' ), get_search_query() ); ?></h1>
</header><!-- .page-header -->
<?php
$query = new WP_Query( array( 's' => get_query_var('s')) );
// The Loop
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
}
?>
<?php var_dump($the_query) ?>
</section><!-- /#main -->
<?php get_sidebar(); ?>
</div><!-- /#main-sidebar-container -->
<?php get_sidebar( 'alt' ); ?>
</div><!-- /#content -->
<?php woo_content_after(); ?>
<?php get_footer(); ?>
SEARCHFORM.PHP (I got from the twenty twelve theme):
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label for="s" class="assistive-text"><?php _e( 'Search', 'twentyeleven' ); ?></label>
<input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
</form>
I have tried different code for the searchform.php too such as:
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<label class="hidden" for="s"><?php _e('Search:'); ?></label>
<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="GO" />
</form>
and
<form role="search" method="get" id="searchform" class="searchform" action="<?php esc_url( home_url( '/' )); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
<input type="text" value="<?php get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
</form>
and
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<label>
<span class="screen-reader-text">Search for:</span>
<input type="search" class="search-field" placeholder="Search …" value="" name="s" title="Search for:" />
</label>
<input type="submit" class="search-submit" value="Search" />
</form>
But still nothing. When it searches, this is what i get in the url:
http://www.energyhealing.directory/?s=energy&submit=Search
and on the page for that URL it displays:
Search Results for: energy << the title for it
Listed in
Continue Reading << thats a link to nowhere, just comes back to the same page
If someone could just explain to me where I have gone wrong and why, that would be amazing?
Thanks in advance for any help you can give. I look forward to hearing back from you!
Aww ok I see how to post in the question now:
Here is the code from the search.php which just returns the blank page:
<?php
/**
* Search Template
*
* The search template is used to display search results from the native WordPress search.
*
* If no search results are found, the user is assisted in refining their search query in
* an attempt to produce an appropriate search results set for the user's search query.
*
* #package WooFramework
* #subpackage Template
*/
get_header();
global $woo_options;
?>
<!-- #content Starts -->
<?php woo_content_before(); ?>
<div id="content" class="col-full">
<div id="main-sidebar-container">
<!-- #main Starts -->
<?php woo_main_before(); ?>
<section id="main" class="col-left">
<header class="page-header">
<h1 class="page-title"><?php printf( __( 'Search Results for: %s', '' ), get_search_query() ); ?></h1>
</header><!-- .page-header -->
<?php
$query = new WP_Query( array( 's' => get_query_var('s')) );
// The Loop
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
}
?>
</section><!-- /#main -->
<?php get_sidebar(); ?>
</div><!-- /#main-sidebar-container -->
<?php get_sidebar( 'alt' ); ?>
</div><!-- /#content -->
<?php woo_content_after(); ?>
<?php get_footer(); ?>
EDITED (for search.php):
<?php if ( have_posts() ):?>
<ul>
<?php while ( have_posts() ) : the_post();?>
<li><?php the_title();?></li>
<?php endwhile;?>
</ul>
<?php endif;?>
I think the searchform.php is ok, but I don't see a loop anywhere in your search.php
$query = new WP_Query( array( 's' => get_query_var('s')) );
// The Loop
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
}
You need this query to create a loop based on the search.

Previous post is shown after submitting a comment

What is wrong with my code that it results in page going to the previous post after submitting a comment?
This is the webpage.
You may try if you want.
This is the code from comments.php:
<?php
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if ( post_password_required() ) { ?>
This post is password protected. Enter the password to view comments.
<?php
return;
}
?>
<?php if ( have_comments() ) : ?>
<h2 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?></h2>
<div class="navigation">
<div class="next-posts"><?php previous_comments_link() ?></div>
<div class="prev-posts"><?php next_comments_link() ?></div>
</div>
<ol class="commentlist">
<?php wp_list_comments(); ?>
</ol>
<div class="navigation">
<div class="next-posts"><?php previous_comments_link() ?></div>
<div class="prev-posts"><?php next_comments_link() ?></div>
</div>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ( comments_open() ) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<p>Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
<?php if ( comments_open() ) : ?>
<div id="respond">
<h2><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h2>
<div class="cancel-comment-reply">
<?php cancel_comment_reply_link(); ?>
</div>
<?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?>
<p>You must be logged in to post a comment.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ( is_user_logged_in() ) : ?>
<p>Logged in as <?php echo $user_identity; ?>. Log out »</p>
<?php else : ?>
<div>
<input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="author">Name <?php if ($req) echo "(required)"; ?></label>
</div>
<div>
<input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="email">Mail (will not be published) <?php if ($req) echo "(required)"; ?></label>
</div>
<div>
<input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" />
<label for="url">Website</label>
</div>
<?php endif; ?>
<!--<p>You can use these tags: <code><?php echo allowed_tags(); ?></code></p>-->
<div>
<textarea name="comment" id="comment" cols="58" rows="10" tabindex="4"></textarea>
</div>
<div>
<input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<?php comment_id_fields(); ?>
</div>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
I read this question but don't understand what the solution is.
What do I do to get <?php do_action( 'comment_form', $post->ID ); ?> to behave as expected?
UPDATE:
This is my single.php and as you see, $post is set so don't know what the issue can be:
<?php get_header(); ?>
<nav>
<?php wp_nav_menu(array('menu' => 'Main Nav Menu')); ?>
</nav>
<div id="main-content">
<div class="post-bg-single">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="post-title-single"><h2><?php the_title(); ?></h2></div>
<h5 class="date-single">Posted on <?php the_time(get_option('date_format')); ?></h5>
<div class="separator-up-single"></div>
<div class="thumbnail-single"><?php
if( has_post_thumbnail() ){
echo get_the_post_thumbnail(); // or just simply, the_post_thumbnail()
}
?></div>
<div class="entry">
<?php the_content(); ?>
<h5 class="expand">Expand post area</h5>
<!-- <h5 class="print">Printable version</h5> -->
</div>
<div class="separator-down"></div>
<h5 class="categories">Categories: <?php the_category(', ') ?></h5>
<h5 class="tags"><?php the_tags('Tags: ', ', ', '<br />'); ?></h5>
<h5 class="edit"><?php edit_post_link(__('→ Edit post← '), ''); ?></h5>
</div>
</div>
<h84>Read more:</h84>
<div id="related-posts">
<?php
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'showposts'=>4, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '
<ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<?php $bg_image = post_thumb( get_the_post_thumbnail() );?>
<a href="<?php the_permalink() ?>"><div class="post-bg-archive" style="background: #777777 url(<?php echo $bg_image;?>);">
<div id="title-bg">
<div class="transparency"></div>
<div class="archive-title"><h10><?php the_title(); ?></h10></div>
</div>
</div></a>
<?php
}
echo '</ul>';
}
}
?>
</div>
<div class="comments-bg">
<?php comments_template(); ?>
</div>
<?php endwhile; endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
When you do a new WP_Query, it overwrite the global $post variable with the new query.
Either try get_posts() and rewriting the query or add in wp_reset_query(); right before calling comments_template();
wp_reset_query(); would be the fastest way to get it displaying properly.

Resources