Skip Navigation

[Resolved] Custom Shortcode

This support ticket is created 4 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 1 voice.

Last updated by garyN-2 4 years, 2 months ago.

Author
Posts
#1766627

Tell us what you are trying to do?I am trying to execute a custom shortcode. I wrote the shortcode as:

add_shortcode( 'rvr-update-author', 'rvr_update_author_function' );
function rvr_update_author_function( $atts ) {
$a = shortcode_atts( array('userid' => '3'), $atts );
$userid = $a['userid'];
get_user_data(userid);
$user_email = $user_info->user_email;
$loop = new WP_Query( array( 'post_type' => 'rally', 'posts_per_page' => -1) );
while ( $loop->have_posts() ) : $loop->the_post();
function_alert ("Rally Email: ".get_post_meta(get_the_ID(),'wpcf-rallyemail',true));
if(get_post_meta(get_the_ID(),'wpcf-rallyemail',true)== $user_email )
{
$arg = array(
'ID' => get_the_ID(),
'post_author' => $userid,
);
wp_update_post( $arg );
}
endwhile;
wp_reset_postdata();
}

1. I placed this code in the functions.php file.
2. I added a new page
3. I typed [rvr-update-author] in a text paragraph
4. I clicked - Publish

Wordpress indicates that it failed to publish.

Is there any documentation that you are following?Yes: https://toolset.com/documentation/adding-custom-code/how-to-create-a-custom-shortcode/

Is there a similar example that we can see?

What is the link to your site?rvrally.net

#1766677

It turns out to be a block editor problem.