• Resolved Creatium

    (@creatium)


    Hi,

    So I’m currently playing around with this plugin checking out what are the options and if I can do what I want to do. Trying to place ad groups in Archive page, but failing. So I am using a manual placement with PHP code. Reading support page I made these changes in settings:
    – Unlimited ad injection set to -1 (also tried 0 and 1)
    – Priority of content injection filter (tried 0 and 100)
    – Disable leve limitation – checked (tried with unchecked too)

    Nothing seems to help. If I place the code in any other page, everything starts working. What am I missing? Dont have any display conditions set, tried in Incognito mode too. No errors in debug log either.

    P.S. No caching plugin is running, also no plugins that are in your list of unsupported.

    • This topic was modified 2 years, 8 months ago by Creatium.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support schmidt25

    (@schmidt25)

    Hi Creatium

    Thanks for sharing your problem.

    I guess you will place the ads between posts on your archive page. We provide in our manual about how to inject ads into the loop a description that includes code snippets.

    This manual is not universal, as this integration is theme-dependent but rather a starting point for further customization.

    Alternatively, you can simply catch this spot using the Post Lists Placement.

    If you plan to embed AdSense in-feed ads on these positions, our free plugin “In-feed ads for Google AdSense” might also cover your needs.

    Best regards,
    Joachim

    Thread Starter Creatium

    (@creatium)

    Hi. Thanks for a reply.

    Since I’m using manual placement, I tried to add it in the top of archive.php file (next to get_header(), but still not working. Also tried just out of “if have_posts()”. I wasn’t trying to add it inside while loop if that’s what you meant.

    Plugin Support schmidt25

    (@schmidt25)

    Hi Creatium,

    Thanks for the clarification. I misunderstood your request, sorry.

    Can you verify that you edit the correct archive.php? If you make any other changes to that file, is there any change in the frontend?

    Which theme do you use?

    Best regards,
    Joachim

    Thread Starter Creatium

    (@creatium)

    I am using a theme created by myself, pure html, css and jquery, no builders.

    And yes, correct file. I have added a sample text inside
    if( function_exists('the_ad_placement') ) and it shows up. But ads dont. And again, tried to add this code in other files, like single.php and they work. Also strangely enough they work in search.php file.

    Plugin Support schmidt25

    (@schmidt25)

    Thanks. Can you please enable the ad debug mode for this ad unit and check if you see any output in your frontend?

    Thread Starter Creatium

    (@creatium)

    No and yes. Enabling debug mode did nothing. But I went through my functions and some of them were to adjust archive and search results (to also query custom table for specific field).

    These functions look like this:

    function archive_search_join( $join ) {
        global $pagenow, $wpdb;
    
        if ((is_search() || is_archive()) && !is_admin() && 'edit.php' !== $pagenow) {    
            $join .=' LEFT JOIN '.$wpdb->prefix.'customtable pm ON '. $wpdb->posts . '.ID = pm.post_id ';
        }
    
        return $join;
    }
    add_filter('posts_join', 'archive_search_join' );

    And this one does the trouble (disabling it – ads start showing up):

    function archive_search_where( $where ) {
        global $pagenow, $wpdb;
        $custom_values = "'value 1', 'value 2'";
    
        if(is_archive() && !is_admin() && 'edit.php' !== $pagenow) {
    	$where .= " AND pm.custom_field IN (".$custom_values.")"; 
        }
    
        return $where;
    }
    add_filter( 'posts_where', 'archive_search_where', 10 );

    So probably my filters are intercepting ad queries and causing the issue of ads not being found.

    Thread Starter Creatium

    (@creatium)

    Worth noting is that in search.php I also use similar filter to filter out results by custom table field. The problem is somehow with this specific line:

    $where .= " AND pm.custom_field IN (".$custom_values.")";

    Plugin Support schmidt25

    (@schmidt25)

    Thanks for the code snippets.

    Unfortunately, your question exceeds my technical skills and does not seem to be directly related to Advanced Ads, but to the custom code.

    I will ask the team if anybody has an idea to give you a helpful hint here.

    Best regards,
    Joachim

    Thread Starter Creatium

    (@creatium)

    Hi. I have managed to fix my issue by adding another check in filter if statements:

    $query->is_main_query()

    This makes sure that filters are applied only to the main archive query and not any side queries (like sidebars and ad queries).

    Thanks for you help, it was a good pointer.

    Plugin Support schmidt25

    (@schmidt25)

    Hi creatium,

    I forgot to follow up. Thomas wanted to add a comment here, but noticed that you was able to resolve this issue by yourself. Congratulations.

    If you have any further questions about Advanced Ads in the future, please, don’t hesitate to open a new thread here in the forums.

    Best regards and stay safe,
    Joachim

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Manual placement on Archive’ is closed to new replies.