• Resolved Darren Cooney

    (@dcooney)


    Hello,
    Fantastic plugin you have here, congratulations!

    I have a small issue where auto placement ads are not rendering when being fetched via wp-admin/admin-ajax requests. However, if I add the advertisements via shortcode ([the_ad id="15"]) directly into the posts, it is displayed when returned via admin-ajax.

    Do you think there is a hook/filter that is not firing in my the_content() call?

    Here is a modified version of template admin-ajax is returning.

    <article class="the-post">
       <h1><?php the_title(); ?>
       <?php 
          $postid = get_the_ID();
          $content = do_shortcode(get_post_field( 'post_content', $postid ));
          $content = apply_filters('the_content', $content);
          echo $content; 
       ?>
    </article>

    Any help is greatly appreciated.

    Thanks in advanced ??

    • This topic was modified 5 years, 9 months ago by Darren Cooney. Reason: better explanation
Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Thomas Maier

    (@webzunft)

    Hi dcooney,

    thanks for your kind words about Advanced Ads.

    The automatic injection is disabled if you have the “Disable ads in Secondary Queries” option enabled. Please check in Advanced Ads > Settings > General if that is the case.

    This would be the most simple explanation. Let me know if changing that option doesn’t help.

    Thomas

    Thread Starter Darren Cooney

    (@dcooney)

    @webzunft That is not disabled.
    Do you happen to know which class method injects the ads?
    I can check if that class is available in admin-ajax requests

    Plugin Author Thomas Maier

    (@webzunft)

    Hi dcooney,

    yes, you can start at the inject_content class advanced-ads/public/class-advanced-ads.php.

    Maybe, it has to do with $wp_query not being set to the current post.

    I am curious to learn what you find out.

    Thomas

    Thread Starter Darren Cooney

    (@dcooney)

    Hi @webzunft,
    Thanks so much! I narrowed down the issue to the following on line 452:

    if ( ( ! is_singular( $public_post_types ) && ! is_feed() ) || ( ! $is_amp && ! in_the_loop() ) ) {
    	return $content; 
    }

    If I remove this if statement, ads are automatically added.
    Not really sure what the blocker is on this line but I’d love to figure it out because many users of my infinite scroll plugin are using Advanced Ads.

    Plugin Author Thomas Maier

    (@webzunft)

    Hi Darren,

    I would be happy to make our plugins compatible.

    Does your plugin create a loop in the WordPress, like documented on https://codex.www.ads-software.com/The_Loop? That could be the problem and the check if in_the_loop() could prevent the injection.

    Would you be able to test it by just removing that condition?

    Thanks,
    Thomas

    Thread Starter Darren Cooney

    (@dcooney)

    Hi Thomas,
    It does create a loop, but in_the_loop() and is_feed() are returning false in the Ajax call.

    while ($alm_query->have_posts()): $alm_query->the_post();
    // Code here
    endwhile;

    If I remove the in_the_loop() OR the_feed() condition it still fails.

    If I remove everything and just leave if ( ( !is_singular( $public_post_types ) )) it fails also.

    Seems like I have a few issues here around the_loop and is_singular,

    ?? Ideas? ??

    • This reply was modified 5 years, 9 months ago by Darren Cooney.
    Plugin Author Thomas Maier

    (@webzunft)

    Hi dcooney,

    let me take another look myself.

    Do I just enable your plugin and use a content placement or does it need some work to set it up and reproduce the problem?

    Thanks,
    Thomas

    Thread Starter Darren Cooney

    (@dcooney)

    Hi Thomas,
    Yes, activate the plugin and then add the [ajax_load_more] shortcode to a new page.

    You will want to visit Ajax Load More > Repeater Templates and update the template to use the_content() instead of the_excerpt().

    Let me know if that makes sense.

    Hi @dcooney and @webzunft ,

    I am an user of Advanced ads (which has my thumbs up) and recently I wanted to integrate infinite scroll (using Ajax Load More) … to my surprise they seem not to be able to work together.

    My ads from advanced ads do not show when using ALM …

    I would definitely love to be able to use both of your plugins for this as they are both amazing….

    Can you please keep working on this and make them work together?

    Thank a lot for your help
    Gustav

    Plugin Author Thomas Maier

    (@webzunft)

    Hi development2go,

    the ball is in my corner now. I am going to set up a test site and see what I can do about this. It was just a busy start in the new week and I hope to get to this some.

    Thomas

    hi @webzunft ,

    I would be highly grateful to you for your efforts on making it work. I would honestly hate not only because of loss of time but to have to remove such a fantastic plugin as yours as we move dozens of sites to infinite scroll…

    not to mention that most of my clients (at least 6 of them) have the paid version of your plugin… ??

    Thanks a lot
    G

    Plugin Author Thomas Maier

    (@webzunft)

    Hi dcooney,

    I found the problem and it is rather obvious when I am thinking about it now.

    While Ajax Load More correctly uses WP_Query, it does not replace the main query. is_singular() and in_the_loop() used in Advanced Ads check the main query only.

    Advanced Ads does prevent injection into non-main-queries by default, because it would trigger ads everywhere where the_content is used and that happens a lot even before content is loaded.

    You can just set Unlimited Injection to any positive value or to -1 to allow ad injection into posts loaded by your plugin.

    I would not want to circumvent this, but if you think there could be a better out-of-the-box behavior then please let me know.

    Thomas

    Thread Starter Darren Cooney

    (@dcooney)

    Hi @webzunft,
    Ok got it now.

    FYI – In the Single Posts add-on @development2go is using I manually set is_singular and is_single to true.

    Adding in_the_loop solves this issue ??

    Final code.

    global $wp_query;
    $wp_query->is_single = true;
    $wp_query->is_singular = true;         
    $wp_query->in_the_loop = true;

    Thanks for the help! Excellent plugin you have here.

    Plugin Author Thomas Maier

    (@webzunft)

    Perfect. I will also start a page in our manual where I mention this solution and your plugin.

    Thomas

    Hi @webzunft, @dcooney,

    So what would be the final solution to this problem for me?
    do i need to manually modify code on any of the plugins?

    let me know
    Thanks a lot
    G

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Ads not showing in admin-ajax requests’ is closed to new replies.