Site icon Hip-Hop Website Design and Development

Alter question utilizing pre_get_posts() if meta_key is current

I’m attempting to switch the variety of posts per web page for archive pages that include class sticky posts (added by the Class Sticky put up plugin)

to take action I’m utilizing the pre_get_postshook and have tried the next :

add_action( 'pre_get_posts', 'my_set_category_posts_per_page' );

operate my_set_category_posts_per_page( $question ) {

  world $wp_the_query;

  if ( 'category_sticky_post' === $query->get( 'meta_key' ) && ! is_paged ) {

        $query->set( 'posts_per_page', 8 );

  }

  return $question;
}

I var_dump($question) I do get [meta_key] => category_sticky_post within the query_vars however I can not type out the way to use it.

One other concept is to make use of one thing like this:

operate my_set_category_posts_per_page( $question ) {

  $args = array(
        array(
            'key'     => 'category_sticky_post',
            'examine' => 'EXISTS'
        )
    );
    $meta_query = new WP_Meta_Query($args);

    if ( 'category_sticky_post' === $query->get('meta_query', $meta_query) && ! is_paged() ) {

       $query->set( 'posts_per_page', 8 );

    }
}

How would I alter the question solely when the meta secret’s current for the posts within the present question?