Site icon Hip-Hop Website Design and Development

FacetWP paging customized wp_query

firstly the overview of what I am making an attempt to realize. I am constructing a useful resource middle which lists out numerous customized put up sorts and it is filterable/searchable because of FacetWP. Inside this itemizing of belongings I’m inserting a "promo" put up sort at each sixth spot, therefore the customized question, which is:

add_filter('facetwp_query_args', perform ($query_args, $class) {

if ('resource_library_parent' == $class->ajax_params['template']) {
    // promos question
    $promos = get_posts(array(
        'posts_per_page' => -1,
        'post_type'      => 'promo',
        'facetwp'        => false,
        'orderby'        => 'menu_order'
    ));

    // belongings question
    $belongings = get_posts(array(
        'posts_per_page' => -1,
        'post_type'      => array('report', 'e-book', 'whitepaper', 'casestudy', 'webinar', 'device', 'infographic'),
        'post_status'    => 'publish',
        'has_password'   => false,
        'facetwp'        => false,
        'orderby'        => 'date',
        'tax_query'      => array(array(
            'taxonomy'   => 'tag',
            'discipline'      => 'slug',
            'phrases'      => 'hide-me',
            'operator'   => 'NOT IN'
        ))
    ));

    $x = 6;

    foreach ($belongings as $num => $asset) {
        if (($num + 1) % $x == 0) {
            if (isset($promos[($num + 1) / $x - 1])) {
                array_splice($belongings, $num, 0, array($promos[($num + 1) / $x - 1]));
            }
        }
    }

    foreach ($belongings as $asset) {
        $posts_id[] = $asset->ID;
    }

    $query_args['post_type'] = array('report', 'e-book', 'whitepaper', 'casestudy', 'webinar', 'device', 'infographic', 'promo');
    $query_args['post__in'] = $posts_id;
    $query_args['orderby'] = 'post__in';
    $query_args['posts_per_page'] = 12;
}
return $query_args;
}, 10, 2);

This works superbly on web page load.

However clicking by way of the pagination (utilizing the pager aspect sort) leads to the second web page of outcomes lacking the following "promo" at place 18. Refreshing the second web page leads to the promo displaying on the appropriate spot – place 6 or 18 of the overall. Clicking again to web page one leads to all 3 "promo" posts being displayed, once more refreshing fixes the ordering.

It is driving me across the bend and little doubt it has one thing to do with the pager or me altering the question within the improper place, however ANY hints or concepts can be most welcome.

You may see a demo of this in motion right here: https://staging-xucobuce.kinsta.cloud/resource-center