• Resolved winterstreet

    (@winterstreet)


    I have a function to hide events in the category “Private” on the archive page:

    /* Hide Private categeory events*/
    function hide_eo_private_pre_get_posts( $query ) {
    if (
    ! is_admin() && is_post_type_archive(‘event’)
    ) {
    $tax_query = array(
    ‘post_type’ => ‘event’,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘event-category’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘private’,
    ‘operator’ => ‘NOT IN’,
    ),
    ),
    );
    $query->set( ‘tax_query’, $tax_query );
    }
    }
    add_action( ‘pre_get_posts’, ‘hide_eo_private_pre_get_posts’ );

    Which works. But then it puts a bunch of random pages in the site’s main navigation. I’m not a PHP expert so I’m hoping this is obvious to someone.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter winterstreet

    (@winterstreet)

    I figured this out in case it helps someone else.

    I replaced the line:
    if ( !is_admin() && is_post_type_archive(‘event’) )

    with:
    if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'event' ) )

Viewing 1 replies (of 1 total)

The topic ‘PHP function causes menu change’ is closed to new replies.