Skip Navigation

[Resolved] Insert php to post type

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 6 replies, has 2 voices.

Last updated by nadavL 1 year, 9 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2419231

Hi,

Is it possible to insert a PHP code into a specific post type build with Toolset?

I have a rating plugin, and I need to display specific data from that plugin using PHP.

Thanks,
Nadav

#2419275

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

You need to create a shortcode using WordPress standard methods:

https://developer.wordpress.org/reference/functions/add_shortcode/

You can add the PHP code inside that shortcode, and you can add the whole code to Toolset:

https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#

After that, you need to create a content template and assign it to the post type and use the shortcode there:

https://toolset.com/glossary/template/

Thanks

#2419287

Thank you for this, but I'm afraid I have an error.

I don't really know PHP but I got this code from the plugin developer:
<?php echo (esc_html(YasrMultiSetData::returnMultiSetAverage)): ?>

Later he wrote: "Typo, is ; at the end of the line"

I tried adding the text to a new customer code and got an error. I tried changing it a bit according to some samples I saw on the links you sent and wrote this:
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
[echo (esc_html(YasrMultiSetData::returnMultiSetAverage))];
?>

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

I still have a warning, and I'm not sure why.

Any chance you can understand what's wrong with the info I provided?

Thanks

#2420461

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

This is something that you need to consult with the plugin developer or hire a developer to check. We are unable to check the validity of someone else's PHP code.

Having said that, the correct code should be something like this:

<?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.

echo (esc_html(YasrMultiSetData::returnMultiSetAverage));

Please consider that I do not know what YasrMultiSetData::returnMultiSetAverage section of the code does as it seems to be a custom static class call.

You need to contact the developer who created that code.

Thanks

#2420481

Thanks,
I've contacted the plugin developer and made the adjustments you and him suggested.
Now the are no errors.

But I still can't figure out to add that 'Custom code snippets' to the post template. I've tried adding ShortCode block and write the snippet name, but it didn't work.

Thanks

#2421419

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

We mentioned the documentation on how to add a shortcode. If the documentation is not what you can implement please consider getting help from a developer.

You can find a list here:

https://toolset.com/contractors/

The only thing that I can suggest is to wrap the code that you have inside a shortcode such as:

<?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.

add_shortcode( 'chrcustomcode', 'chr_custom_code_func' );
function chr_custom_code_func() {
    echo (esc_html(YasrMultiSetData::returnMultiSetAverage));
}

Then you will be able to use the Shortcode block in the content template and add [chrcustomcode] there as the shortcode value.

If it does not work for you you need to get help from a developer.

Thanks.

#2424033

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.