Home › Toolset Professional Support › [Resolved] custom code snippet not executing
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 3 replies, has 2 voices.
Last updated by Christopher Amirian 1 year, 10 months ago.
Assisted by: Christopher Amirian.
Tell us what you are trying to do? use custom code snippet with a shortcode on a page but it appears as [shortcode] and doesn't execute.
Is there any documentation that you are following?
Is there a similar example that we can see?
What is the link to your site? hidden link
Hi there,
Would you please make sure you followed the steps below?
If the issue persists, please use the CODE button above the reply box to share the code that you added to see if we can check.
Thanks.
I don't see a code button but here's my code. i've disabled all plugins and have default theme running - everything seems to match the test site where this code DOES work. the table headings are displaying but no data. I can get a simple get user custom code to run so it appears to be just this custom code. thank you!
<?php /** * New custom code snippet (replace this with snippet description). */ toolset_snippet_security_check() or die( 'Direct access is not allowed' ); // Put the code of your snippet below this comment. function multiple_rgs($atts) { $filtered_posts = get_view_query_results( 109 ); $output ="<table> <thead> <tr> <th>Post title</th> <th>Post ID</th> <th>Order Archive Order Date</th> <th>Order Archive Order Number</th> <th>Order Archive Order ID</th> <th>Order Archive Transaction ID</th> <th>Order Archive Paypal Receipt ID</th> <th>Order Archive Username</th> <th>Order Archive Customer First Name</th> <th>Order Archive Customer Last Name</th> <th>Order Archive Item Name</th> <th>Order Manual Item Name</th> <th>Order Manual Item</th> <th>Item Type</th> <th>Order Archives Amount</th> </tr> </thead><tbody>"; foreach ( $filtered_posts as $filtered_post ) { $pid = $filtered_post->ID; $child_posts = toolset_get_related_posts( $pid, 'order-archive-manual', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) ); //print_r($child_posts); $field1 = get_post_meta($pid,'wpcf-order-archive-order-date',true); $dates = date("F j, Y", $field1); $field2 = get_post_meta($pid,'wpcf-order-archive-order-date-text',true); $ordernumb = get_post_meta($pid,'wpcf-order-archive-order-number',true); $orderid = get_post_meta($pid,'wpcf-order-archive-order-id',true); $transid = get_post_meta($pid,'wpcf-order-archive-transaction-id',true); $paypal = get_post_meta($pid,'wpcf-order-archive-paypal-receipt-id',true); $username = get_post_meta($pid,'wpcf-order-archive-username',true); $cfirst = get_post_meta($pid,'wpcf-order-archive-customer-first-name',true); $clast = get_post_meta($pid,'wpcf-order-archive-customer-last-name',true); $arcitemname = types_render_field( "order-archive-product-name", array("item" =>$pid,"seperator" => '<br/>' ) ); $numbrepeat = count($child_posts); if($child_posts) { foreach($child_posts as $repeated) { $omanitemname = get_post_meta($repeated->ID,'wpcf-order-archive-order-manual-item',true); $omanitem = get_post_meta($repeated->ID,'wpcf-order-archive-order-manual-qty',true); $omanitemtype = types_render_field( "item-type", array("item" => $repeated->ID)); $orarcamt = get_post_meta($repeated->ID,'wpcf-order-archives-amount',true); $output .= "<tr>"; $output .= "<td>".$filtered_post->post_title."</td>"; $output .= "<td>".$filtered_post->ID."</td>"; $output .= "<td>".$dates."</td>"; $output .= "<td>".$ordernumb."</td>"; $output .= "<td>".$orderid."</td>"; $output .= "<td>".$transid."</td>"; $output .= "<td>".$paypal."</td>"; $output .= "<td>".$username."</td>"; $output .= "<td>".$cfirst."</td>"; $output .= "<td>".$clast."</td>"; $output .= "<td>".$arcitemname."</td>"; $output .="<td>".$omanitemname."</td>"; $output .= "<td>".$omanitem."</td>"; $output .="<td>".$omanitemtype."</td>"; $output .="<td>".$orarcamt."</td>"; $output .= "</tr>"; } } else { $output .= "<tr>"; $output .= "<td>".$filtered_post->post_title."</td>"; $output .= "<td>".$filtered_post->ID."</td>"; $output .= "<td>".$dates."</td>"; $output .= "<td>".$ordernumb."</td>"; $output .= "<td>".$orderid."</td>"; $output .= "<td>".$transid."</td>"; $output .= "<td>".$paypal."</td>"; $output .= "<td>".$username."</td>"; $output .= "<td>".$cfirst."</td>"; $output .= "<td>".$clast."</td>"; $output .= "<td>".$arcitemname."</td>"; $output .="<td>".$omanitemname."</td>"; $output .= "<td>".$omanitem."</td>"; $output .="<td>".$omanitemtype."</td>"; $output .="<td>".$orarcamt."</td>"; $output .= "</tr>"; } } $output .="</tbody></table>"; return $output; } add_shortcode('multiple_rgs','multiple_rgs');
Thank you for the code snippet. I think the code is ok except the fact that you returned the data instead of echoing it.
So please replace:
return $output;
With;
echo $output;
The other point is that the shortcode needs to be placed in a post that has the_content function and it will not work inside a widget or a place that the WordPress post loop is not there.
Thanks.