Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - -
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - -

Supporter timezone: Asia/Jerusalem (GMT+02:00)

This topic contains 3 replies, has 2 voices.

Last updated by Itamar 10 months, 4 weeks ago.

Assisted by: Itamar.

Author Posts
March 19, 2024 at 1:08 pm #15426494

cornelisS

I am trying to:
Only show dutch events on the dutch website. But once I publish a English event it still gets posted on the dutch website. I tried suppress_filters.

Link to a page where the issue can be seen:
hidden link

I expected to see:
Only the Dutch events on the dutch website.

Instead, I got:
Not see the English webinar on the dutch website.

March 19, 2024 at 7:44 pm #15428651

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi,

I can see one event in English in the link you provided here. Please see the attached screenshot. In the same section, I don't see any Dutch events at all.

Can you please share with us the code that you have to output this?

Thanks,
Itamar.

2024-03-19_21-41-21.jpg
March 22, 2024 at 12:19 pm #15440414

cornelisS

Below the English event you can see the dutch events. This is my code.

<?php
function cl_create_events_posttype() {
register_post_type( 'events',
// CPT Options
array(
'labels' => array(
'name' => __( 'Events' ),
'singular_name' => __( 'Events' )
),
'public' => true,
'has_archive' => false,
'supports' => array('title', 'editor', 'revisions', 'featured', 'thumbnail', 'excerpt'),
'menu_icon' => 'dashicons-download',
'show_in_rest' => true, // gutenberg
'rewrite' => array( 'slug' => 'evenementen', 'with_front' => false ), )
);
}

// Hooking up our function to theme setup
add_action( 'init', 'cl_create_events_posttype' );

function contentleaders_events( $atts = array() ){
$excerpt_word_count = 17;

if ( isset( $atts['limit'] ) ) {
$limit = $atts['limit'];
$facet = false;
} else {
$limit = 9;
$facet = true;
}

if ( isset($atts['past']))
$past = $atts['past'];

if ( isset($atts['home_host']))
$home_host = $atts['home_host'];

if ($past) {
$args = array(
'post_status' => 'publish',
'post_type' => 'events',
'posts_per_page'=> '-1',
'suppress_filters' => true,
'meta_query' => [
[
'key' => 'date_start',
'value' => date('Y-m-d'),
'compare' => '<=',
'type' => 'DATE'
]
],
'meta_key' => 'date_start',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
} else if($home_host == 'Informed Group') {
$args = array(
'order' => 'ASC',
'orderby' => 'meta_value_num',
'meta_key' => 'date_start',
'suppress_filters' => true,
'meta_type' => 'DATE',
'post_status' => 'publish',
'post_type' => 'events',
'posts_per_page'=> '-1',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'date_start',
'value' => date('Y-m-d'),
'compare' => '>=',
'type' => 'DATE'
),
array(
'key' => 'event_host',
'value' => 'Informed Group',
'compare' => '=='
)
)
);
$args['posts_per_page'] = -1;
} else {
$args = array(
'order' => 'ASC',
'orderby' => 'meta_value_num',
'meta_key' => 'date_start',
'meta_type' => 'DATE',
'post_status' => 'publish',
'suppress_filters' => true,
'post_type' => 'events',
'posts_per_page'=> '-1',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'date_start',
'value' => date('Y-m-d'),
'compare' => '>=',
'type' => 'DATE'
),
array(
'key' => 'event_host',
'value' => 'Anders',
'compare' => '=='
)
)
);
$args['posts_per_page'] = -1;
}

if ( isset( $atts['excerptlength'] ) )
$excerpt_word_count = intval( $atts['excerptlength'] );
if ( isset($atts['titlelength']))
$title_word_count = intval( $atts['titlelength'] );

$actual_link = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

$leesmeer = 'Lees meer';

if (strpos($actual_link, ".com")) {
$leesmeer = 'Read more';
}

$string = '<div class="cl-nieuws-container">';
$query = new WP_Query( $args );
if( $query->have_posts() ){
$x = 0;
while ( $query->have_posts() ) {
$query->the_post();

$excerpt = get_the_excerpt();
$title = get_the_title();
// $host = get_field('event_host');

$title = wp_trim_words($title, $title_word_count);
$excerpt = wp_trim_words($excerpt, $excerpt_word_count);

$string .= '';
$string .= '

';
$string .= get_the_post_thumbnail();
$string .= '

';
$string .= '

' . $title . '

';
$string .= '' . get_field('date_label') . '';
$string .= '

' . $excerpt . '

';
$string .= '

' . $leesmeer . '

';
$string .= '

';
$string .= '

';
$string .= '
';

}
}else{
$string .= 'Geen events gevonden.';
}
$string .= '</div>';
wp_reset_query();

return $string;
}
add_shortcode('events', 'contentleaders_events');

?>

March 24, 2024 at 9:28 am #15443677

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi, and thanks for sharing your code.

For your information, we have extensive developer documentation. The main page of it is here.

https://wpml.org/documentation/support/

It seems that your code lacks the out following hook.

https://wpml.org/wpml-hook/wpml_object_id/

The wpml_object_id returns an element’s ID in the current language or another specified language. You need to use it in your code. Please see the examples and adjust your code.

The following link to our guide on Debugging Theme Compatibility can also help you fix the problem. See the Issue: wp_query($args) or get_posts($args) doesn’t filter out correct posts IDs for the current language.

https://wpml.org/documentation/support/debugging-theme-compatibility/#issue-wp_queryargs-or-get_postsargs-doesnt-filter-out-correct-posts-ids-for-the-current-language

You might be using suppress_filters incorrectly, and you need to use it like this:

suppress_filters=0

Please let me know if this information is helpful to you.

Regards,
Itamar.

The topic ‘[Closed] My WP_query isnt filtering on Dutch or English. My shortcode is showing both.’ is closed to new replies.