I requested AI ChatGPT:
Are you able to develop a wordpress shortcode to create an inventory of customers of a sure position and for every one present in the event that they commented on a sure publish (counting what number of feedback they left)? The shortcode ought to write an inventory of customers and for every one say: “Sure commented (variety of feedback left)“, or “No”.
That is the reply:
perform my_custom_shortcode( $atts ) {
$atts = shortcode_atts( array(
'post_id' => 0, // default worth for publish ID
'position' => '', // default worth for person position
), $atts );
// get the listing of customers who've commented on the publish
$customers = get_users_who_commented( $atts['post_id'], $atts['role'] );
// generate the output for the shortcode
$output="<ul>";
foreach ( $customers as $person ) {
$num_comments = get_number_of_comments_by_user( $atts['post_id'], $user->ID );
if ( $num_comments > 0 ) {
$output .= '<li>Sure, commented (' . $num_comments . ' feedback)</li>';
} else {
$output .= '<li>No</li>';
}
}
$output .= '</ul>';
return $output;
}
add_shortcode( 'users_who_commented', 'my_custom_shortcode' );
he It was so good to even present me use the shortcode.. all the things appeared good.
[users_who_commented post_id="123" role="author"]
.. nevertheless it would not work, “wp-die-message” seems on the web page as an alternative of the magic shortcode output. Why?
Can anybody beat the unreal intelligence?
Am I asking the flawed query in the appropriate place?
Thanks
Perhaps this can assist:
Deadly error: Uncaught Error: Name to undefined perform get_users_who_commented() in /.../wp-content/themes/responsive/features.php:1106 Stack hint: #0 /.../wp-includes/shortcodes.php(355): my_custom_shortcode(Array, '', 'users_who_comme...') #1 [internal function]: do_shortcode_tag(Array) #2 /.../wp-includes/shortcodes.php(227): preg_replace_callback('/[([?)(uccoun...', 'do_shortcode_ta...', 'n<p><span style...') #3 /.../wp-includes/class-wp-hook.php(308): do_shortcode('n<p><span style...') #4 /.../wp-includes/plugin.php(205): WP_Hook->apply_filters('n<p><span style...', Array) #5 /.../wp-includes/post-template.php(255): apply_filters('the_content', '<!-- wp:paragra...') #6 /.../wp-content/themes/responsive/partials/page/content.php(15): the_content('Leggi altro ...') #7 /.../wp-includes/template. in /.../wp-content/themes/responsive/functions.php on line 1106