I try to modify the Query in custom post type archives created in Toolset->Wordpress Archives with "wpv_filter_query" filter hook. It is possible? This code didn't work (it's nothing changing on page):
add_filter( 'wpv_filter_query', 'modify_text_testimonials_query', 101, 3 );
function modify_text_testimonials_query( $query_args, $view_settings, $view_id ) {
if( is_post_type_archive( 'text-testimonials' ) ){
$query_args['post__in'] = my_custom_array(1, 2, 3);
$query_args['orderby'] = 'post__in';
}
return $query_args;
}
I was try to modify code like Minesh wrote here: https://toolset.com/forums/topic/display-only-the-latest-post-with-duplicated-taxonomy/
But this code didn't work too (it's nothing changing on page).
Basically, i prepare array with post ID's, ordered by current site language (WPML). And after, i want to replace the $query_args['post__in'] with that array. How to do that with "View Archives" feature?
Here is my code to prepare array with ID's:
function sort_text_testimonials_by_language() {
$post_ids = array();
$current_page_language = apply_filters( 'wpml_current_language', NULL );
$current_page_language_post_ids = get_posts( [
'post_type' => 'text-testimonials',
'post_status' => 'publish',
'meta_key' => 'wpcf-original-language',
'meta_value' => $current_page_language,
'posts_per_page' => -1,
'fields' => 'ids',
'order' => "DESC",
'orderby' => 'date'
] );
$all_post_ids = get_posts( [
'post_type' => 'text-testimonials',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'wpcf-original-language',
'value' => $current_page_language,
'compare' => '!=',
'type' => 'CHAR'
)
),
'fields' => 'ids',
'order' => "DESC",
'orderby' => 'date'
] );
$post_ids_merged = array_merge( $current_page_language_post_ids, $all_post_ids );
$post_ids = array_unique( $post_ids_merged );
return $post_ids;
}