admin管理员组文章数量:1425016
I have a Wordpress AJAX call that is working in as much as it is able to get raw data from a PHP file. The AJAX is using the admin-ajax.php file. However, the PHP file I need to get is within the loop of the page. Where it is being placed is where it works if it was just included on the page.
To summarize: if the PHP file being AJAXed has in it:
<?php echo 'this is the file!' ?>
…everything works fine. But if it has:
<?php the_title(); ?>
…it returns blank.
Thank you for taking the time to read this!
I have a Wordpress AJAX call that is working in as much as it is able to get raw data from a PHP file. The AJAX is using the admin-ajax.php file. However, the PHP file I need to get is within the loop of the page. Where it is being placed is where it works if it was just included on the page.
To summarize: if the PHP file being AJAXed has in it:
<?php echo 'this is the file!' ?>
…everything works fine. But if it has:
<?php the_title(); ?>
…it returns blank.
Thank you for taking the time to read this!
Share Improve this question edited Jun 19, 2019 at 16:14 jons asked Jun 19, 2019 at 15:46 jonsjons 1291 silver badge5 bronze badges1 Answer
Reset to default 0There is no such thing as an AJAX call that's inside the loop. The server has no idea what page or where on that page an ajax call is coming from unless you explicitly send it that data as a part of the ajax call. You're going to need to send some data to the php function so it can recreate the correct query (or the current post if that's all you need.) i.e. You send a post ID in the ajax, the php function it calls then does $post_id = $_POST[post_id];
(please add your own sanitization and validation here.) Then instead of calling the_title()
you would call get_the_title($post_id)
本文标签: Wordpress AJAX PHP(html) file that is within Wordpress Loop
版权声明:本文标题:Wordpress AJAX PHP(html) file that is within Wordpress Loop 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745388283a2656476.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论