Filtering posts in blog page by language and category
-
Hi, i have a problem with filtering posts in blog page template, i use polylang plugin and i want to display posts by language slug and category id at one time, i.e. :
– in blog page i display posts from category “news”, i have 3 languages on my page, each language have it’s own news category
english – “news”
deutsch – “neuigkeiten”
norge – “nyheter”So i write this code to filter posts by language slug and category id, but i know its hard coded in wrong way, it works until i use pagination.
<?php $currentlang = get_bloginfo('language'); if ($currentlang == 'en-US') { query_posts('cat=3'); }; if ($currentlang == 'de-DE') { query_posts('cat=56'); }; if ($currentlang == 'nn-NO') { query_posts('cat=58'); }; ?>I have added this upper code before this posts loop in blog template:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>It works until i add pagination, then i get double quantity of posts from news category in particular language, could you tell what i’m doing wrong?. I know that problem is in IF statement, because when i cut this code, pagination works well but display all posts unfiltered (as it normally should in this situaton). It’s look like filtering IF statement doesn’t cut unneeded posts from results, it not display them, but pagination see number of all posts and gives overall quantity of pages for them, i saw it when i minimized max number of post per page in wordpress generalsettings->reading panel.
So my final question is how to correctly filter posts by language slug and category id at one time?
Morten66
The topic ‘Filtering posts in blog page by language and category’ is closed to new replies.