admin管理员组文章数量:1296503
I'm loading comments with AJAX. It all works fine except reply link isn’t being rendered on the page. As I understand, the problem is can’t pass $args. How would I access $args or max_depth outside the callback?
Ajax template :
<?php
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
if (isset($_POST['id']) && $_POST['id']) {
$comments = get_comments(array('post_id' => $_POST['id']));
foreach ($comments as $comment) {
$GLOBALS['comment'] = $comment;
?>
<div class="comment">
<?php comment_text(); ?>
<div class="comment__reply">
<?php
comment_reply_link (
array_merge(
$args,
array(
'reply_text' => __( 'Répondre ', 'autourdesanimaux' ),
'depth' => $depth,
'max_depth' => get_option( 'thread_comments_depth' )
)
)
);
?>
</div>
</div>
<?php }
} ?>
This code is not recognized (I am in a custom ajax)
array_merge(
$args,
array(
'reply_text' => __( 'Répondre ', 'autourdesanimaux' ),
'depth' => $depth,
'max_depth' => get_option( 'thread_comments_depth' )
)
)
Thank you
This post doesn't explain how to access $args Load custom formatted comment with AJAX: reply link isn’t rendered?
I'm loading comments with AJAX. It all works fine except reply link isn’t being rendered on the page. As I understand, the problem is can’t pass $args. How would I access $args or max_depth outside the callback?
Ajax template :
<?php
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
if (isset($_POST['id']) && $_POST['id']) {
$comments = get_comments(array('post_id' => $_POST['id']));
foreach ($comments as $comment) {
$GLOBALS['comment'] = $comment;
?>
<div class="comment">
<?php comment_text(); ?>
<div class="comment__reply">
<?php
comment_reply_link (
array_merge(
$args,
array(
'reply_text' => __( 'Répondre ', 'autourdesanimaux' ),
'depth' => $depth,
'max_depth' => get_option( 'thread_comments_depth' )
)
)
);
?>
</div>
</div>
<?php }
} ?>
This code is not recognized (I am in a custom ajax)
array_merge(
$args,
array(
'reply_text' => __( 'Répondre ', 'autourdesanimaux' ),
'depth' => $depth,
'max_depth' => get_option( 'thread_comments_depth' )
)
)
Thank you
This post doesn't explain how to access $args Load custom formatted comment with AJAX: reply link isn’t rendered?
Share Improve this question asked Apr 3, 2021 at 8:09 aroharoh 132 bronze badges 1- 1 You shouldn't be loading WP in a standalone PHP file, it's extreme bad practice, it's insecure, fragile, and has lots of other problems. If you need to make AJAX calls use the REST API to handle them, or at least the old admin AJAX API – Tom J Nowell ♦ Commented Apr 3, 2021 at 20:19
1 Answer
Reset to default 0You do not need an existing $args
variable here, you can define your own arguments and they will override the defaults. See the get_comment_reply_link() docs for the defaults.
Instead, you can pass the arguments you want directly.
comment_reply_link( array(
'reply_text' => __( 'Répondre ', 'autourdesanimaux' ),
'depth' => $depth,
'max_depth' => get_option( 'thread_comments_depth' )
) );
The $depth
variable will need to be set, and it needs to be greater than zero and less than max_depth
. This article describes how to get a comment's depth by checking for the parent
property on WP_Comment
objects and counting.
本文标签: Loading comments in ajaxcommentreply function missing args
版权声明:本文标题:Loading comments in ajax - comment-reply function missing $args 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741636775a2389683.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论