Skip Navigation

[Resolved] Adding an ‘Edit link’ to a php template

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to add a toolset-edit-post-link shortcode in a PHP template.

Solution: It's probably easier to just create your own HTML link using the appropriate format, and output that with PHP. Here is the format:

https://yoursite.com/cpt-slug/post-slug/?content-template-id=12345
This support ticket is created 5 years, 1 month 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by JamesS2731 5 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1471927

Tell us what you are trying to do? I'm trying to add an edit link to a venue custom post type, but the post type doesn't have a content template, but a php template instead. I've followed the instructions listed below but, in the last instruction, instead of adding the link to the single post content template, I need to add it to a php template.

The code I wish to add is:

{!{toolset-edit-post-link content_template_slug='edit-club-template' target='self'}!}Edit %%POST_TITLE%%{!{/toolset-edit-post-link}!}

I've tried adding it to a page, then linking to that page, but I just get a blank page.

Is there any documentation that you are following? https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-editing/

Is there a similar example that we can see? hidden link

What is the link to your site? hidden link

Any thoughts or ideas greatly appreciated as always.

Kind regards
James

#1471999

Hi, if I understand correctly you want to add an Edit Post link in a PHP template. A toolset-edit-post-link shortcode added in wp-admin will produce on the front-end a simple link tag with href URL in the following format:

<em><u>hidden link</u></em>

With that in mind, you could echo a basic HTML link using this format in PHP, instead of using the toolset-edit-post-link shortcode:

echo "<a href='<em><u>hidden link</u></em>;" . get_the_title( $post_id ) . "</a>";

Change cpt-slug to your post type slug, change post-slug to the post slug, and change 12345 to the numeric ID of the Content Template containing your edit post Form. The get_the_title( $post_id ) bit is just an example of retrieving the post title, you may need to alter the post ID code depending on how your PHP template is set up.

Let me know if I misunderstood what you want to accomplish and I can offer some different feedback. Thanks!

#1472041

Hi Christian,

Many thanks for your quick reply. Yes, you've understood that perfectly. My only question is what to use for the post slug as that will be dynamic (the name of the club).

My shortcake looks like:

echo "hidden link">" . get_the_title( $post_id ) . "";

An example club link

hidden link

If I manually ass /sxs-racing/ as the post-slug the link works, so what would be the best shortcode to use in it's place.

Apologies as I should know this!

Kind regards
James

#1472067

You can access the post's slug in PHP as a post field called 'post_name':

$post_slug = get_post_field( 'post_name', $post_id );

Then use $post_slug in your URL instead of get_the_title(). A list of those post member variables like slug, title, excerpt, etc. can be found here:
https://codex.wordpress.org/Class_Reference/WP_Post#Member_Variables_of_WP_Post

#1473289

Perfect! That did the trick.

For reference in case anyone else has the same issue, here's what I used in the end:

<?php echo "Edit " . get_the_title( $post_id ) . ""; ?>

Many thanks for your help.

Kind regards
James