Dies ist das technische Support-Forum für WPML - das mehrsprachige WordPress-Plugin.

Mitlesen können alle, doch nur WPML-Kunden können hier Fragen veröffentlichen. Das WPML-Team beantwortet Anfragen im Forum an 6 Tagen pro Woche, 22 Stunden am Tag.

Schlagwörter: 

This topic contains 4 Antworten, has 2 Teilnehmer.

Last updated by Andreas W. vor 1 Monat.

Assigned support staff: Andreas W..

Author Artikel
September 9, 2019 um 3:04 pm #4538263

joernJ

There is a more complex loop in my theme where some categories are excluded. But that doesn't work on the translated view. Every parameter in wp_query() works fine except category__not_in. I even added the category ids of the french version of the categories which I need to get excluded. Are there some known issues with wp_query() ?

<?php
$queryObject = new Wp_Query( array(
'showposts' => 7,
'post_type' => array('post'),
'category__not_in' => array( 11, 12 ),
'suppress_filters' => false,
'orderby' => 1,
));

// The Loop
if ( $queryObject->have_posts() ) :
$i = 0;
while ( $queryObject->have_posts() ) :
$queryObject->the_post();
if ( $i == 0 ) : ?>

- - - - loop content goes here - - - -

<?php endif;
$i++;
endwhile;
endif;
?>

September 10, 2019 um 2:45 pm #4546523

Andreas W.
Supporter

Languages: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Thank you for contacting the WPML Support Forum.

As far I understand the French post categories with the ID´s 11 and 12 should be exculded on the translated page and the same function with respective taxonomy IDs was working for excluding categories on default language, correct?.

I would advise you to debug the code the following way:

Run var_dump on both arrays of the translated page and check fopr the outcome. Try to run the var_dump on the first and second if statement and also check the result of the while statement between both.

// The Loop
if ( $queryObject->have_posts() ) :
echo "First if statement results in:";
var_dump($queryObject);
$i = 0;
while ( $queryObject->have_posts() ) :
echo "While Statement results in:";
var_dump($queryObject);
$queryObject->the_post();
echo "Final output is:";
var_dump($queryObject);
if ( $i == 0 ) : ?>

The var_dump will print a boolean and the output of the array.

hidden link

Also try to change the line: 'suppress_filters' => true,

Let me know about the outcome.

Kind regards
Andreas

September 10, 2019 um 3:25 pm #4546825

joernJ

Hallo Andreas,

(schätze, wir können auf deutsch weiter machen). Die folgenden beiden outputs kamen dabei heraus. Die beiden category IDs (55,63), die im var_dump des If-Statements aufgeführt werden, sind die IDs der französischen Übersetzung und sind in meinem Wp_Query auch bereits mit ausgeschlossen worden. Trotzdem wird der Post aus dieser ID angezeigt (der aus dem zweiten var_dump output)

First if statement results in:object(WP_Query)#3019 (50) { ["query"]=> array(5) { ["showposts"]=> int(7) ["post_type"]=> array(1) { [0]=> string(4) "post" } ["category__not_in"]=> array(4) { [0]=> int(11) [1]=> int(12) [2]=> int(55) [3]=> int(63) } ["suppress_filters"]=> bool(false) ["orderby"]=> int(1) } ["query_vars"]=> array(67) { ["showposts"]=> int(7) ["post_type"]=> array(1) { [0]=> string(4) "post" } ["category__not_in"]=> array(2) { [0]=> int(55) [1]=> int(63) } ["suppress_filters"]=> bool(false) ["orderby"]=> string(1) "1" ["error"]=> string(0) "" ["m"]=> string(0) "" ["p"]=> int(0) ["post_parent"]=> string(0) "" ["subpost"]=> string(0) "" ["subpost_id"]=> string(0) "" ["attachment"]=> string(0) "" ["attachment_id"]=> int(0) ["name"]=> string(0) "" ["static"]=> string(0) "" ["pagename"]=> string(0) "" ["page_id"]=> int(0) ["second"]=> string(0) "" ["minute"]=> string(0) "" ["hour"]=> string(0) "" ["day"]=> int(0) ["monthnum"]=> int(0) ["year"]=> int(0) ["w"]=> int(0) ["category_name"]=> string(0) "" ["tag"]=> string(0) "" ["cat"]=> string(0) "" ["tag_id"]=> string(0) "" ["author"]=> string(0) "" ["author_name"]=> string(0) "" ["feed"]=> string(0) "" ["tb"]=> string(0) "" ["paged"]=> int(0) ["meta_key"]=> string(0) "" ["meta_value"]=> string(0) "" ["preview"]=> string(0) "" ["s"]=> string(0) "" ["sentence"]=> string(0) "" ["title"]=> string(0) "" ["fields"]=> string(0) "" ["menu_order"]=> string(0) "" ["embed"]=> string(0) "" ["category__in"]=> array(0) { } ["category__and"]=> array(0) { } ["post__in"]=> array(0) { } ["post__not_in"]=> array(0) { } ["post_name__in"]=> array(0) { } ["tag__in"]=> array(0) { } ["tag__not_in"]=> array(0) { } ["tag__and"]=> array(0) { } ["tag_slug__in"]=> array(0) { } ["tag_slug__and"]=> array(0) { } ["post_parent__in"]=> array(0) { } ["post_parent__not_in"]=> array(0) { } ["author__in"]=> array(0) { } ["author__not_in"]=> array(0) { } ["meta_query"]=> array(0) { } ["ignore_sticky_posts"]=> bool(false) ["cache_results"]=> bool(true) ["update_post_term_cache"]=> bool(true) ["lazy_load_term_meta"]=> bool(true) ["update_post_meta_cache"]=> bool(true) ["posts_per_page"]=> int(7) ["nopaging"]=> bool(false) ["comments_per_page"]=> string(2) "10" ["no_found_rows"]=> bool(false) ["order"]=> string(4) "DESC" } ["tax_query"]=> object(WP_Tax_Query)#3062 (6) { ["queries"]=> array(1) { [0]=> array(5) { ["taxonomy"]=> string(8) "category" ["terms"]=> array(2) { [0]=> int(55) [1]=> int(63) } ["field"]=> string(7) "term_id" ["operator"]=> string(6) "NOT IN" ["include_children"]=> bool(false) } } ["relation"]=> string(3) "AND" ["table_aliases":protected]=> array(0) { } ["queried_terms"]=> array(0) { } ["primary_table"]=> string(11) "sa1fl_posts" ["primary_id_column"]=> string(2) "ID" } ["meta_query"]=> object(WP_Meta_Query)#3064 (9) { ["queries"]=> array(0) { } ["relation"]=> NULL ["meta_table"]=> NULL ["meta_id_column"]=> NULL ["primary_table"]=> NULL ["primary_id_column"]=> NULL ["table_aliases":protected]=> array(0) { } ["clauses":protected]=> array(0) { } ["has_or_relation":protected]=> bool(false) } ["date_query"]=> bool(false) ["request"]=> string(1415) "SELECT SQL_CALC_FOUND_ROWS sa1fl_posts.ID FROM sa1fl_posts LEFT JOIN sa1fl_icl_translations wpml_translations ON sa1fl_posts.ID = wpml_translations.element_id AND wpml_translations.element_type = CONCAT('post_', sa1fl_posts.post_type) WHERE 1=1 AND ( sa1fl_posts.ID NOT IN ( SELECT object_id FROM sa1fl_term_relationships WHERE term_taxonomy_id IN (55,63) ) ) AND sa1fl_posts.post_type = 'post' AND (sa1fl_posts.post_status = 'publish' OR sa1fl_posts.post_status = 'private') AND ( ( ( wpml_translations.language_code = 'fr' OR ( wpml_translations.language_code = 'de' AND sa1fl_posts.post_type IN ( 'post','page' ) AND ( ( ( SELECT COUNT(element_id) FROM sa1fl_icl_translations WHERE trid = wpml_translations.trid AND language_code = 'fr' ) = 0 ) OR ( ( SELECT COUNT(element_id) FROM sa1fl_icl_translations t2 JOIN sa1fl_posts p ON p.id = t2.element_id WHERE t2.trid = wpml_translations.trid AND t2.language_code = 'fr' AND ( p.post_status = 'publish' OR p.post_type='attachment' AND p.post_status = 'inherit' ) ) = 0 ) ) ) ) AND sa1fl_posts.post_type IN ('post','page','attachment','wp_block','displayed_gallery' ) ) OR sa1fl_posts.post_type NOT IN ('post','page','attachment','wp_block','displayed_gallery' ) ) GROUP BY sa1fl_posts.ID ORDER BY sa1fl_posts.post_date DESC LIMIT 0, 7" ["posts"]=> array(7) { [0]=> object(WP_Post)#3054 (24) { ["ID"]=> int(151) ["post_author"]=> string(5) "54955" ["post_date"]=> string(19) "2019-09-06 22:25:34" ["post_date_gmt"]=> string(19) "2019-09-06 20:25:34" ["post_content"]=> string(1421) "

" ["post_title"]=> string(50) "Sit hoc ultimum bonorum, quod nunc a me defenditur" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(49) "sit-hoc-ultimum-bonorum-quod-nunc-a-me-defenditur" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2019-09-10 16:57:53" ["post_modified_gmt"]=> string(19) "2019-09-10 14:57:53" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(24) "hidden link" ["menu_order"]=> int(0) ["post_type"]=> string(4) "post" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } [1]=> object(WP_Post)#3058 (24) { ["ID"]=> int(98) ["post_author"]=> string(5) "54955" ["post_date"]=> string(19) "2019-09-01 13:41:15" ["post_date_gmt"]=> string(19) "2019-09-01 11:41:15" ["post_content"]=> string(11892) "

September 10, 2019 um 3:34 pm #4546913

joernJ

Sehe gerade: die ID (98) aus dem var_dump des Posts ist die falsche. Sie gehört nicht zu diesem Post, sondern zu dem nächsten, der regulär angezeigt werden soll (und auch wird).

September 10, 2019 um 5:09 pm #4547607

Andreas W.
Supporter

Languages: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hallo,

Um ehrlich zu sein Umfasst mein Wissen rund um PHP nicht die nötige Grundlage, um Ihnen individuelle Ratschläge zu erteilen, was auch über unsere Support-Richtlinien normalerweise ausgeschlossen ist, aber sollte mein Vorschlag nicht zur einer Lösung führen, konsultiere ich gerne unseren L2 Support daraufhin.

Ich verstehe richtig, dass der Loop auf der Standardsprache funktioniert, aber auf den übersetzen seiten nicht die gewünschten Posts anzeigt.

Diesbezüglich sollte das Problem somit nicht am Code, sondern daran liegen, dass WPML die postIDs nicht richtig zuweisen kann.

Haben Sie es eventuelle einmal mit einem Foreach Loop probiert?

Beispiel:

$array_keys = array(
'category__in',
'category__not_in',
'category__and',
'post__in',
'post__not_in',
'post_name__in',
'tag__in',
'tag__not_in',
'tag__and',
'tag_slug__in',
'tag_slug__and',
'post_parent__in',
'post_parent__not_in',
'author__in',
'author__not_in',
);

foreach ( $array_keys as $key ) {
if ( ! isset( $array[ $key ] ) ) {
$array[ $key ] = array();
}
}
return $array;

Mit freundlichen Grüßen
Andreas

Das Thema ‘[Geschlossen] Wp_Query() – Exclusion of categoies is not transfered’ ist für neue Antworten geschlossen.