Wordpress pagination not working in search results - php

I have this search.php with the results of my search by year/genre:
<?php get_header();
$loop = new TOROFLIX_Movies();
$sidebar_position = $loop->sidebar_position('sidebar_type_category'); ?>
<div class="Body">
<div class="Main Container">
<?php get_template_part('public/partials/template/letters'); ?>
<div class="TpRwCont <?php echo $sidebar_position; ?>">
<main>
<section>
<div class="Top AAIco-movie_filter">
<h2 class="Title">
<?php if(isset($_GET['genre']) or isset($_GET['years'])){
echo 'Afisez ce doreste sufletul tau! :)';
} else {
echo get_search_query();
} ?>
</h2>
</div>
<ul class="MovieList Rows AX A04 B03 C20 D03 E20 Alt">
<?php if(isset($_GET['genre']) or isset($_GET['years'])){ ?>
<?php $args = array(
'post_type' => array('movies', 'series'),
'posts_per_page' => get_option( 'posts_per_page' ),
'post_status' => 'publish',
'no_found_rows' => true,
'ignore_sticky_posts' => true,
);
if( isset( $_GET['genre'] ) && $_GET['genre'] != '' ){
$args['tax_query'][] = array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $_GET['genre']
);
}
if( isset( $_GET['years'] ) && $_GET['years'] != '' ){
$args['tax_query'][] = array(
'taxonomy' => 'annee',
'field' => 'term_id',
'terms' => $_GET['years']
);
}
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
get_template_part("public/partials/template/loop-principal");
endwhile;
endif; wp_reset_query(); ?>
<?php } else{
if(have_posts()) :
while(have_posts()) : the_post();
get_template_part("public/partials/template/loop-principal");
endwhile; ?>
<?php else: ?>
<div>
<?php _e('There are no articles', 'toroflix'); ?>
</div>
<?php endif;
} ?>
</ul>
</section>
</main>
<?php if($sidebar_position != 'NoSdbr'){ get_sidebar(); } ?>
</div>
</div>
</div>
<?php get_footer(); ?>
The settings for
'posts_per_page' => get_option( 'posts_per_page' ),
in wordpress are to display 200 results. I want those results to be paged, let's say 20 posts per page then next, next.. Inside the page, no other links for results page.
I tried to add
<nav class="wp-pagenavi">
<?php echo TOROFLIX_Add_Theme_Support::toroflix_pagination(); ?>
</nav>
, a code that I got from the Category page, where paginations works without problem, but does not display anything related to pagination in search results.
The Category page code is:
<?php get_header();
$loop = new TOROFLIX_Movies();
$sidebar_position = $loop->sidebar_position('sidebar_type_category'); ?>
<div class="Body">
<div class="Main Container">
<?php $alphabet = get_option('alphabet_show');
if($alphabet){
get_template_part('public/partials/template/letters');
} ?>
<div class="TpRwCont <?php echo $sidebar_position; ?>">
<main>
<section>
<div class="Top AAIco-movie_filter">
<h2 class="Title"><?php single_cat_title(); ?></h2>
</div>
<ul class="MovieList Rows AX A04 B03 C20 D03 E20 Alt">
<?php if(have_posts()) :
while(have_posts()) : the_post();?>
<?php get_template_part("public/partials/template/loop-principal"); ?>
<?php endwhile; ?>
<?php else: ?>
<div>
<?php _e('There are no articles', 'toroflix'); ?>
</div>
<?php endif; ?>
</ul>
<nav class="wp-pagenavi">
<?php echo TOROFLIX_Add_Theme_Support::toroflix_pagination(); ?>
</nav>
</section>
</main>
<?php if($sidebar_position != 'NoSdbr'){ get_sidebar(); } ?>
</div>
</div>
</div>
<?php get_footer(); ?>
and the category's navigation works just fine, how can I get the same results on the search page results?

I'm not familliar with the Trolofix functions, but have you tried using the default WP
the_posts_pagination()
https://developer.wordpress.org/reference/functions/the_posts_pagination/
or
paginate_links()
https://developer.wordpress.org/reference/functions/paginate_links/
Also try to figure out what OROFLIX_Add_Theme_Support::toroflix_pagination() does?
This might give you a clue on how to add your own pagination on the search.php file

Related

Multiple loops: exclude a post returned in loop 1 from loop 2

I have two wp_query loops.
The first loop looks for a featured post and formats it differently than the rest of the posts.
Then the second loop displays the rest of the posts.
I want to exclude this first, featured post from the rest of the loop.
Right now, the post ID of the first post is saved as a variable.
I want to use that variable in the second loop, with the wp_query exclude argument.
But as far as I understand, that variable dies when my first loop ends. It's then a null variable in the second loop and so nothing is excluded.
<!-- Here's the query for the featured post -->
<?php
// the arguments
$args = array(
'posts_per_page' => '1',
'orderby' => '',
'meta_key' => 'featured_post',
'meta_value' => '1'
); ?>
<?php $the_query = new WP_Query($args); ?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<!-- I'm storing the ID so I can exclude it from the rest of the loop, but I know this doens't work right now -->
<?php $postid = get_the_ID(); ?>
<div class="small-12 columns entry" >
<div class="text-center" id="featured-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('featured'); ?>
</a>
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php
$content = get_the_content();
echo wp_trim_words($content, '75');
?>
</p>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<!-- If there is no featured post, pull in the most recent post and make it big -->
<?php else: ?>
<?php
// the arguments
$args = array(
'posts_per_page' => '1',
'orderby' => '',
); ?>
<?php $the_query = new WP_Query($args); ?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<!-- I'm storing the ID so I can exclude it from the rest of the loop, but I know this doens't work right now -->
<?php $postid = get_the_ID(); ?>
<div class="small-12 columns entry" >
<div class="text-center" id="featured-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('featured'); ?>
</a>
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php
$content = get_the_content();
echo wp_trim_words($content, '75');
?>
</p>
</div>
</div>
<!-- End of the nested loop (most recent posts) -->
<?php endwhile; ?>
<?php endif; ?>
<!-- End of the featred post query loop-->
<?php endif; ?>
And here's the main loop:
<?php get_template_part('parts/content', 'featured-post'); ?>
<!-- This ends the logic for the featured post. Now we show the rest of the posts, excluding the first one we showed -->
<?php get_template_part('parts/content', 'category-filter'); ?>
<?php
// the arguments
$args=array(
'paged' => $paged,
'posts_per_page' => 9,
'post__not_in' => array($postid)
); ?>
<?php $the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- Start row that holds blocks -->
<div class="row small-up-1 medium-up-2 large-up-3">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="column entry" >
<?php if( get_the_post_thumbnail() ): ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('blog'); ?>
</a>
<?php else : ?>
<?php endif; ?>
<h5><?php the_title(); ?></h5>
<?php
$excerpt = get_the_excerpt();
echo wp_trim_words( $excerpt , '10', '');
?>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>Sorry, no more posts.</p>
<?php endif; ?>
How exactly do I set up a variable to use in the second loop?

Editing PHP grid page for WordPress site

I would like to Edit the Grid Artist page to only have 12 artists and land on the producers section instead of all artist.
Here' s the link of website page : http://cascaderecords.fr/roster/
PHP code:
<?php
if (ci_setting('artists_isotope') == 'enabled' AND !wp_is_mobile() AND !is_tax() ):
?>
<ul class="filters-nav group">
<li><?php _e('All Artists', 'ci_theme'); ?></li>
<?php
$args = array('hide_empty' => 1);
$cats = get_terms('artist-category', $args);
?>
<?php foreach ( $cats as $cat ): ?>
<li><?php echo $cat->name; ?></li>
<?php endforeach; ?>
</ul>
<?php
endif; // is isotope enabled
global $paged;
if ( ci_setting('artists_isotope') == 'enabled' AND !wp_is_mobile() AND !is_tax() ) {
$args = array(
'post_type' => 'cpt_artists',
'posts_per_page' => -1
);
} else {
$args = array(
'post_type' => 'cpt_artists',
'posts_per_page' => ci_setting('artists_per_page'),
'paged' => $paged
);
}
$the_query = !empty($the_query) ? $the_query : new WP_Query($args);
?>
<article class="row">
<ul class="col-md-12 items-list-grid filter-container <?php echo $filter; ?>">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $cats = wp_get_object_terms($post->ID, 'artist-category'); ?>
<li class="<?php foreach ( $cats as $cat ) : echo $cat->slug.' '; endforeach; echo $grid; ?>">
<article id="artist-<?php the_ID(); ?>" <?php post_class('row'); ?>>
<div class="col-md-12">
<?php if ( has_post_thumbnail() ) : ?>
<figure>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('ci_thumb_square'); ?>
</a>
</figure>
<?php endif; ?>
<h2><?php the_title(); ?></h2>
</div><!-- /col-md-12 -->
</article><!-- /row -->
</li><!-- /col-md-4 -->
<?php endwhile; wp_reset_postdata(); ?>
</ul>
Try change:
'posts_per_page' => -1
to:
'posts_per_page' => 12
Not sure what "ci_setting('artists_per_page')" is in below variable, need more info:
'posts_per_page' => ci_setting('artists_per_page'),

WordPress loop alternate rows and columns each two posts with bootstrap

I want to create a loop for wordpress that returns each two posts inside its own div and alternating columns every new row (see example)... Im not experimented in php enough to make this happen. I dont manage to get it working appropiatly. And see how to make the last div to bee 100% width if it does not have another column.
I would appreciate your support to make this happen since I tried many things and still no luck. (im using visual composer bootstrap classes, it does work but not as expected.This is the example I want to create
This is my code:
<?php
$args = array(
'posts_per_page' => '-1',
'post_type' => 'inversion',
'category_name' => '',
'order' => 'DESC',
'orderby' => 'DATE'
);
$the_query = new WP_Query( $args );?>
<?php if ( $the_query->have_posts() ) : ?>
<div class="vc_row">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); $i++; $imagen = get_the_post_thumbnail_url(get_the_ID(),'full'); ?>
<?php if(($i % 2) == 2) : ?>
<div class="vc_col-sm-6">
<div class="vc_row vc_row-fluid">
<div class="vc_col-sm-6 cont-izq">
<h3><?php the_title(); ?></h3>
</div>
<div class="vc_col-sm-6 cont-der" >
<a class="click-info">Más Información</a>
<div class="img-dentro kenburns-top" style="background:url(<?php echo $imagen; ?>)no-repeat; background-size:cover;">
</div>
</div>
</div>
</div>
<?php else : ?>
<div class="vc_col-sm-6">
<div class="vc_row vc_row-fluid">
<div class="vc_col-sm-6 cont-der" >
<a class="click-info">Más Información</a>
<div class="img-dentro kenburns-top" style="background:url(<?php echo $imagen; ?>)no-repeat; background-size:cover;">
</div>
</div>
<div class="vc_col-sm-6 cont-izq">
<h3><?php the_title(); ?></h3>
</div>
</div>
</div>
<?php endif; endwhile; ?>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
[EDIT]Try this:
<?php
$args = array(
'posts_per_page' => '-1',
'post_type' => 'inversion',
'category_name' => '',
'order' => 'DESC',
'orderby' => 'date',
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<div class="vc_row">
<?php
$float_class = '';
while ( $the_query->have_posts() ) :
$the_query->the_post();
if ( $the_query->current_post &&
$the_query->current_post % 2 === 0 ) {
$float_class = $float_class ? '' : 'vc_pull-right';
}
$imagen = get_the_post_thumbnail_url( get_the_ID(), 'full' );
?>
<div class="vc_col-sm-6">
<div class="vc_row vc_row-fluid">
<div class="vc_col-sm-6 cont-der <?php echo $float_class; ?>">
<a class="click-info">Más Información</a>
<div class="img-dentro kenburns-top" style="background:url('<?php echo esc_url( $imagen ); ?>') no-repeat; background-size:cover;">
</div>
</div>
<div class="vc_col-sm-6 cont-izq">
<h3><?php the_title(); ?></h3>
</div>
</div>
</div>
<?php endwhile; // end have_posts() loop ?>
</div><!-- .vc_row -->
<?php endif; // end have_posts() check ?>
<?php wp_reset_query(); ?>

WordPress pagination doens't work on home

I created a WordPress template file with latest posts and pagination. But when I set this page as the home page, the pagination wont work and it'll display the first page. As a standalone page it does work. Strange! Any thoughts about this?
<?php get_header(); ?>
<div id="primary" class="content-area clr">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article class="homepage-wrap clr">
<?php
/**
Post Content
**/ ?>
<?php if ( get_the_content() !== '' ) { ?>
<div id="homepage-content" class="entry clr">
<?php the_content(); ?>
</div><!-- .entry-content -->
<?php } ?>
<?php
/**
Features
**/
$wpex_query = new WP_Query(
array(
'order' => 'ASC',
'orderby' => 'menu_order',
'post_type' => 'features',
'posts_per_page' => '-1',
'no_found_rows' => true,
)
);
if ( $wpex_query->posts ) { ?>
<div id="homepage-features" class="clr">
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-features', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-features -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
/**
Portfolio
**/
$display_count = get_theme_mod('wpex_home_portfolio_count', '8');
$wpex_query = new WP_Query(
array(
'post_type' => 'portfolio',
'posts_per_page' => $display_count,
'no_found_rows' => true,
'tax_query' => wpex_home_portfolio_taxonomy(),
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-portfolio" class="clr">
<h2 class="heading"><span><?php _e( 'Recent Work', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-portfolio', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
$args = array(
'paged' => (get_query_var('paged') ? get_query_var('paged') : 1),
'posts_per_page' => 4
);
query_posts($args);
?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<ul class="post-meta clr">
<li class="meta-date"><?php _e('Posted on','wpex'); ?> <span class="meta-date-text"><?php echo get_the_date(); ?></span> </li>
</ul>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endwhile; ?>
<?php wp_pagenavi();?>
</div><!-- #homepage-portfolio -->
<?php wp_reset_query(); ?>
<?php endif; ?>
</article><!-- #post -->
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
I might have found an answer for this myself, apparently it's different when you use pagination on the frontpage. I used this and it seems to be working!:
if( is_front_page() ){
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
} else {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
}

Use the same page for multiple taxonomies

I need to use the same page for different taxonomies and terms.
How can I retrieve the taxonomies and the terms from the URL and run the same page for those I that I want?
The query should be run through a URL since I am not using forms.
When the user clicks on the link, a new page should be opened that is an archive of posts having custom post type, taxonomy and taxonomy terms specified in the URL.
This is the code that I have right now:
<? /*
* Template Name: Activities template
* Description: Template for activties like restaurants, pubs, etc.
*/
?>
<?php $options = get_option('mh_options'); ?>
<?php get_header(); ?>
<?php
if ( get_query_var('paged') ) {$paged = get_query_var('paged');}
if ( get_query_var('page') ) {$paged = get_query_var('page');}
$args = array(
'post_type' => 'activties',
'tax_query' => array(
array(
'taxonomy' => 'restaurants',
'field' => 'slug',
'terms' => 'italian'
),
'paged' => $paged
)
);
query_posts( $args ); ?>
<div class="wrapper clearfix">
<div class="main">
<div class="content <?php mh_content_class(); ?>">
<?php mh_before_page_content(); ?>
<?php dynamic_sidebar('pages-1'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- <?php the_content(); ?> -->
<article <?php post_class(); ?>>
<div class="loop-wrap loop-layout2">
<div class="clearfix">
<div class="loop-thumb">
<a href="<?php the_permalink(); ?>">
<?php if( get_field('business_logo') ): ?>
<?php $image = wp_get_attachment_image_src(get_field('business_logo'), 'loop'); ?>
<img src="<?php echo $image[0]; ?>" alt="<?php the_field('business_logo');?>" data-thumb="<?php echo $thumb[0]; ?>" />
<?php else: echo '<img src="' . get_template_directory_uri() . '/images/noimage_300x225.png' . '" alt="No Picture" />'; ?>
<?php endif; ?>
</a>
</div>
<div class="loop-content">
<header>
<h3 class="loop-title"><?php the_title(); ?></h3>
</header>
<?php if (get_field('business_description')): ?>
<?php $text_to_trim = get_field('business_description');
echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?>
<?php endif; ?>
<?php if (get_field('business_paying_desc')): ?>
<?php $text_to_trim = get_field('business_paying_desc');
echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?>
<?php endif; ?>
</div>
</div>
</div>
</article>
<?php dynamic_sidebar('pages-2'); ?>
<?php endwhile; ?>
<!-- <?php wp_reset_postdata(); ?> -->
<?php wp_reset_query(); ?>
<?php if (isset($options['comments_pages']) ? $options['comments_pages'] : false) : ?>
<section>
<?php comments_template(); ?>
</section>
<?php endif; ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php mh_second_sb(); ?>
</div>
<?php get_footer(); ?>
EDIT
After a few days, I found the solution that I am going to post, however it has got an issue: I cannot see the list of the posts if a post has got multiple terms (more than 1 term basically) selected by the checkboxes when it is created or edited.
This is my taxonomy.php file
<?php
$post = $wp_query->post;
/*$catMerc = array('restaurants','pubs', 'the-pizzerias', 'bars', 'cafes', 'nightlife-clubs', 'shopping', 'the-coffeeshops');*/
$catMerc = array('the-restaurants', 'the-coffeeshops', 'the-pizzerias', 'shopping', 'nightlife-clubs', 'cafes', 'bars', 'pubs');
$termsObjects = wp_get_object_terms($post->ID, $catMerc);
//Assuming your post only has one category, if theres more it will return multiple objects in it's return array:
$currentCustomCat = $termsObjects[0]->slug;
$currentCatMerc = get_query_var('taxonomy');
//you can have 'name' instead of 'slug' if that helps too
$customcatarray = array('american-pubs-exclusive5', 'american-pubs-in-town', 'beer-houses-exclusive5', 'beer-houses-in-town', 'free-joints-exclusive5', 'free-joints-in-town', 'local-atmosphere-exclusive5', 'local-atmosphere-in-town', 'spanish-atmosphere-exclusive5', 'spanish-atmosphere-in-town', 'take-away-exclusive5', 'take-away-in-town', 'traditional-dutch-exclusive5', 'traditional-dutch-in-town', 'african-exclusive-5', 'african-in-town', 'argentinian-restaurants-exclusive5', 'argentinian-restaurants-in-town',' asian-restaurants-exclusive5', 'asian-restaurants-in-town', 'dutch-restaurants-exclusive5', 'dutch-restaurants-in-town', 'french-restaurants-exclusive5', 'french-restaurants-in-town', 'italian-restaurants-exclusive5', 'italian-restaurants-in-town', 'seafood-restaurants-exclusive5', 'seafood-restaurants-in-town', 'spanish-restaurants-exclusive5', 'spanish-restaurants-in-town', 'cocktail-bars-exclusive5', 'cocktail-bars-in-town', 'disco-bars-exclusive5', 'disco-bars-in-town', 'dutch-bars-exclusive5', 'dutch-bars-in-town', 'internet-cafes-exclusive5', 'internet-cafes-in-town', 'lounge-bars-exclusive5', 'lounge-bars-in-town', 'art-cafes-exclusive5', 'art-cafes-in-town', 'breakfast-lunch-exclusive5','breakfast-lunch-in-town', 'famous-cafes-exclusive5', 'famous-cafes-in-town', 'fashion-cafes-exclusive5', 'fashion-cafes-in-town', 'timeout-exclusive5', 'timeout-in-town', 'best-boutiques-exclusive5','best-boutiques-in-town', 'famous-brands-exclusive5', 'famous-brands-in-town', 'sportswear-exclusive5', 'sportswear-in-town', 'the-pizzerias-with-table-service-in-town', 'the-pizzerias-with-table-service-exclusive5', 'the-pizzerias-takeway-in-town', 'the-pizzerias-takeaway-exclusive5', 'the-coffeeshops-in-town', 'the-coffeeshops-exclusive5');
if (in_array($currentCatMerc, $catMerc) && in_array($currentCustomCat, $customcatarray) ) {include(TEMPLATEPATH.'/page_activities.php'); }
/*if( $currentCustomCat == "italian" || $currentCustomCat == "local-atmosphere"){
//It matched, do stuff here
{include(TEMPLATEPATH.'/single_activities.php'); }
}*/
else { /*include(TEMPLATEPATH.'/page.php'); */
$pagelink=get_page_link (get_page_by_title( 'Homepage' ));
header("Location: $pagelink",TRUE,301);
}
?>
And this is my page_activities.php file
<?php
if ( get_query_var('paged') ) {$paged = get_query_var('paged');}
if ( get_query_var('page') ) {$paged = get_query_var('page');}
$args = array(
'post_type' => 'activities',
'tax_query' => array(
array(
'taxonomy' => $currentCatMerc,
'field' => 'slug',
'terms' => $currentCustomCat
),
'paged' => $paged,
'posts_per_page'=>'10',
)
);
$args2 = array(
'post_type' => 'activities',
'paged' => $paged
);
query_posts( $args ); ?>
<div class="wrapper clearfix">
<div class="main">
<div class="content <?php mh_content_class(); ?>">
<?php mh_before_page_content(); ?>
<?php dynamic_sidebar('pages-1'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- <?php the_content(); ?> -->
<article <?php post_class(); ?>>
<div class="loop-wrap loop-layout2">
<div class="clearfix">
<div class="loop-thumb">
<a href="<?php the_permalink(); ?>">
<?php if( get_field('business_logo') ): ?>
<?php $image = wp_get_attachment_image_src(get_field('business_logo'), 'loop'); ?>
<img src="<?php echo $image[0]; ?>" alt="<?php the_field('business_logo');?>" data-thumb="<?php echo $thumb[0]; ?>" />
<?php else: echo '<img src="' . get_template_directory_uri() . '/images/noimage_300x225.png' . '" alt="No Picture" />'; ?>
<?php endif; ?>
</a>
</div>
<div class="loop-content">
<header>
<h3 class="loop-title"><?php the_title(); ?></h3>
</header>
<?php if (get_field('business_description')): ?>
<?php $text_to_trim = get_field('business_description');
echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?>
<?php endif; ?>
<?php if (get_field('business_paying_desc')): ?>
<?php $text_to_trim = get_field('business_paying_desc');
echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?>
<?php endif; ?>
</div>
</div>
</div>
</article>
<?php dynamic_sidebar('pages-2'); ?>
<?php endwhile; ?>
<!-- <?php wp_reset_postdata(); ?> -->
<?php wp_reset_query(); ?>
<?php endif; ?>
<div class="sb-widget home-2 home-wide">
<h4 class="widget-title">Latest Updates</h4>
<ul class="cp-widget clearfix">
<?php query_posts( $args2 ); ?>
<?php if (have_posts()) : $i=1; while (have_posts() && ($i<=10)) : the_post(); ?>
<li class="cp-wrap cp-small clearfix">
<div class="cp-thumb">
<a href="<?php the_permalink(); ?>">
<?php if( get_field('business_logo') ): ?>
<?php $image = wp_get_attachment_image_src(get_field('business_logo'), 'cp_small'); ?>
<img width="70" height="53" src="<?php echo $image[0]; ?>" alt="<?php the_field('business_logo');?>" data-thumb="<?php echo $thumb[0]; ?>" class="attachment-cp_small wp-post-image" />
<?php endif; ?>
</a></div>
<div class="cp-data">
<p class="cp-widget-title"><?php the_title(); ?></p>
</div>
</li>
<?php $i++; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif;?>
</ul>
</div>
<div class="sb-widget home-2 home-wide">
<?php echo do_shortcode('[rev_slider 620_100]'); ?>
</div>
<?php if (isset($options['comments_pages']) ? $options['comments_pages'] : false) : ?>
<section>
<?php comments_template(); ?>
</section>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php mh_second_sb(); ?>
</div>
<?php get_footer(); ?>
Pls help me with this because I am really clueless.
One good news is that if I check the array with print_r($termsObjects[0]); I can see properly the output.
I guess I should use a foreach somehow, but I don't know where to put my hands on.
Thank you to anyone who can help me with this.
Regards
..your question is a bit broad...but the gist of what you need to do:
to pull the variables from the url
$query = explode('&', $_SERVER['QUERY_STRING']);
$params = array();
foreach( $query as $param ){
list($name, $value) = explode('=', $param);
$params[urldecode($name)][] = urldecode($value);
}
now you will have a params array i've no idea what your urls will look like, but say its '
postterm1 = italian, postterm2 = chinese, etc
$array['taxquery'] = array();
$array['taxquery'][relation]= 'OR';
foreach ($param as $key=>$value) {
$array['taxquery'][]=array(
'taxonomy' => 'restaurants',
'field' => 'slug',
'terms' => $value
);
}
this will build the query you see below, just delete 'tax_query' array and insert the var $array instead. It should work but i haven't tested it so play around with the format if needed.
your custom query (i think you want multi taxonomies but not all?)
Use WP_query:
$args= array(
'post_type' => 'activties',
'tax_query' => array(
'relation'=>'OR',
array(
'taxonomy' => 'restaurants',
'field' => 'slug',
'terms' => 'italian'
),
array(
'taxonomy' => 'restaurants',
'field' => 'slug',
'terms' => 'chinese'
)
),
);
ref: http://codex.wordpress.org/Class_Reference/WP_Query

Categories