Support » Plugin: WPAdverts - Classifieds Plugin » Remove Related ads from Ad Preview Page

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i suppose you are using some snippets to show the “related ads” and “more ads from this person”, if so then in each of the functions that is rendering the related content you need to add something like the code below to show the related content on the ad details pages only

    
    if( ! is_singular( 'advert' ) ) {
      return;
    } 
    
    Thread Starter Carin

    (@sparksfreebies)

    I am using these, any chance you could show me where to put that? Greatly appreciated!

    function related_ads_list_query( $args ) {
        $post = get_post( get_the_ID() );
        
        $args["post__not_in"] = array($post->ID);
        
        // search by keyword
        $args["author"] = $post->post_author;
        
        remove_filter( "adverts_list_query", "related_ads_list_query" );
        return $args;
    }

    and

    function related_ads_tpl_single_bottom( $post_id ) {
    
        add_filter( "adverts_list_query", "related_ads_list_query" );
        
        echo '<h3>' . __( "More ads by this person") . '</h3>';
        echo shortcode_adverts_list( array(
            "redirect_to" => "",
            "search_bar" => "disabled",
            "show_pagination" => 0,
            "posts_per_page" => 5,
            "display" => "list"
        ) );
    }
    Plugin Author Greg Winiarski

    (@gwin)

    Add the code I posted earlier below

    
    function related_ads_tpl_single_bottom( $post_id ) {
    
    Thread Starter Carin

    (@sparksfreebies)

    That worked for Ads by this author, but when I tried to modify Related ads like this it broke the site

    function related_ads_list_query( $args ) {
    if( ! is_singular( 'advert' ) ) {
      return;
    } 
        $post = get_post( get_the_ID() );
        
        $args["post__not_in"] = array($post->ID);
        
        // search by keyword
        $args["author"] = $post->post_author;
        
        remove_filter( "adverts_list_query", "related_ads_list_query" );
        return $args;
    }
    Plugin Author Greg Winiarski

    (@gwin)

    In the realted_ads_list_query() function you would need to change the return; to return $args;, or do not modify the function at all, it should work fine without the modification as well i think.

    Thread Starter Carin

    (@sparksfreebies)

    Hi Greg, and Happy Holidays to you!
    Just to be sure I am doing this right, in order to show the related content on the ad details pages only, I will modify the original snippet to be like this now: (adding $args to the return at top). I want to be sure Related Ads is removed from the Ad Preview Page as it is confusing some of my beta testers.

    function related_ads_list_query( $args ) {
    if( ! is_singular( 'advert' ) ) {
      return $args;
    } 
        $post = get_post( get_the_ID() );
        
        $args["post__not_in"] = array($post->ID);
        
        // search by keyword
        $args["author"] = $post->post_author;
        
        remove_filter( "adverts_list_query", "related_ads_list_query" );
        return $args;
    }
    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    yes, customizing the function like in your code snippet should do it.

    Thread Starter Carin

    (@sparksfreebies)

    Hi Greg, Sorry the Related ads are still showing on the Ad Preview Page, https://www.screencast.com/t/QMQLM8MT

    Plugin Author Greg Winiarski

    (@gwin)

    Can you let me know how does your related_ads_tpl_single_bottom() function look like?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Remove Related ads from Ad Preview Page’ is closed to new replies.