• Hello,

    I am testing some function to modify WP main query. This works fine in the standard blog page but not in pages containg WP show posts shortcodes. Code is as follows. Anything to take into account?
    Thanks!

    `add_action( ‘pre_get_posts’, ‘filtra_posts_roles_usuarios’ );
    function filtra_posts_roles_usuarios( $query )
    {
    if (!$query->is_main_query()
    AND ” === $query->get( ‘s’ )
    )
    return $query;
    $current_user = wp_get_current_user();

    if( ! empty( $current_user ) && in_array( “um_adherente”, (array) $current_user->roles ) ) {
    $query->set( ‘meta_query’, array(
    ‘relation’ => ‘OR’,
    array(
    ‘key’ => ‘um_content_restriction’,
    ‘value’ => ‘um_adherente’,
    ‘compare’ => ‘LIKE’
    ),
    array(
    ‘key’ => ‘um_content_restriction’,
    ‘value’ => ‘um_interno’,
    ‘compare’ => ‘NOT LIKE’
    )
    ) );
    }

    return $query;

    }

Viewing 1 replies (of 1 total)
  • Plugin Support Elvin

    (@ejcabquina)

    Hi there,

    Can you try what happens if you remove AND '' === $query->get( 's' )? on the condition?

Viewing 1 replies (of 1 total)
  • The topic ‘pre_get_posts not working on WP show posts’ is closed to new replies.