[Resolved] Author Box Appearing In Search Results (Even if Disabled)

Home Forums Support [Resolved] Author Box Appearing In Search Results (Even if Disabled)

Home Forums Support Author Box Appearing In Search Results (Even if Disabled)

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2359663
    Adrien

    Hi guys,

    I’m facing an issue with Author Boxes appearing on Search Results.

    Here are two examples:
    https://www.ispeakspokespoken.com/?s=toeic
    https://www.ispeakspokespoken.com/?s=present+perfect

    To display the author boxes, I’m using a PHP snippet that you gave me previously:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        global $post;
        $author = get_post_field( 'post_author', get_the_ID() );
        if ( 21598 === $element_id && '54' === $author || 23592 === $element_id && '32' === $author || 23590 === $element_id && '50' === $author || 23591 === $element_id && '45' === $author ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    So, even if I exclude the author boxes from the search results on the settings, it won’t work.

    Could you please help me with that?

    Thanks a lot,
    Adrien

    #2360023
    Ying
    Staff
    Customer Support

    Try this code instead:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        global $post;
        $author = get_post_field( 'post_author', get_the_ID() );
        if ( 21598 === $element_id && '54' === $author && ! is_search()  || 23592 === $element_id && '32' === $author && ! is_search()  || 23590 === $element_id && '50' === $author  && ! is_search()  || 23591 === $element_id && '45' === $author  && ! is_search()  ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );
    #2361668
    Adrien

    It works like a charm!

    Thanks a lot Ying ๐Ÿ™‚

    #2361962
    Ying
    Staff
    Customer Support

    You are welcome ๐Ÿ™‚

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.