Site logo

Archived topic

Author Box Appearing In Search Results (Even if Disabled)

3 replies · Started by Adrien on October 1, 2022

Viewing posts 1–4 of 4

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

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 );

It works like a charm!

Thanks a lot Ying :)

You are welcome :)

This archived topic is closed to new replies.