Skip Navigation

[Résolu] How to add URL parameter to custom post

This support ticket is created Il y a 8 années et 3 mois. 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.

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.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Marqué : 

This topic contains 11 réponses, has 2 voix.

Last updated by Beda Il y a 8 années et 3 mois.

Assisted by: Beda.

Auteur
Publications
#357356

Hello, I need to pass a url parameter to all custom_posts as in:

example.com/custom_posts?parent_id=param

How can I send the parent post id for example to the url of each custom post like this?

Thanks a lot!

#357404

Where do you need this URL appendix?
In each Posts URL / Slug?

WordPress does not allow social characters in Post Slugs.

If you need to somehow create a list of Posts where the link to them is site.com/slug?parent_id=param, then you can use a mix of ShortCodes and handcrafted HTML in a View or content template.

As example you can use the View ShortCodes and HTML mix as in the below:

[wpv-bloginfo show="url"]/[wpv-post-slug]?parent_id=param

I need to know what you want to achieve, as it seems, you need some kind of Query passed by URL parameter, and for this you can also use Views Query options:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/ > Controlling the filter with URL arguments

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#357559

https://wordpress.org/support/topic/how-to-pass-value-in-wordpress-url

This thread makes it seem possible unless I'm misunderstanding? I don't explicitly need a parameter in the url but was exploring the idea to know how to do it.

I'm actually trying to achieve this:

https://toolset.com/forums/topic/redirect-to-parent-after-cred-delete/

redirecting to parent post after successful custom post deletion. What is the best way to do this? Thanks beda

#357700

Well the easiest and most forward approach is to use Toolset features and not PHP.

Since Toolset Plugins are mainly designed to build Websites without the need of PHP, this is the solution I can suggest:

1. You have a Parent Post Type (parent-post is slug in my example)
2. You have a Child Post Type (child-posts is slug in my example)
3. In the Child Post of a given parent (or in the Content Template where you style the Child Posts) you insert the Delete Post Link as this:
(please remove inline comments to use the code)

[ //Open ShortCode
cred_delete_post_link //define CRED type
class="cred-refresh-after-delete" //Add class
text="Delete %TITLE%"  //Delete Text
redirect="[wpv-post-id id='$parent-post']" //Redirect Post ID ==> See how I use a Types Post ID with id="your_parent_type_slug"
action="trash" //Define action 
message="Are you sure you want to delete this post?" //Define Message
message_show="1" //If to show the message
] //Close ShortCode

If you now hit on the Delete Link in the Child Post, this will redirect to the Parent of the given post.

You can not do that in a CRED form that creates a actual Child Post during the creation process, because the post does not really exist at this point, and therefore there is nothing to delete.

But if the Child Post exists, above is the best and easiest approach.

Here again the full code to use (adjust your "parent post slug")

[cred_delete_post_link class="cred-refresh-after-delete" text="Delete %TITLE%" redirect="[wpv-post-id id='$general-parent']" action="trash" message="Are you sure you want to delete this post?" message_show="1"]

Thank you

#357891

Thanks for the reply Beda, so doing this code within my template means:

do_shortcode( '[cred_delete_post_link class="cred-refresh-after-delete" text="Delete %TITLE%" redirect="[wpv-post-id id='$general-parent']" action="trash" message="Are you sure you want to delete this post?" message_show="1"]');

However the single quote in the [wpv-post-id id='$general-parent'] ends the shortcode early it seems because the shortcode is wrapped in ' '. Is there a way around this?

#358268

The ShortCode Syntax I provided is to be used as a ShortCode within the WP Editors, as you usually do when using Toolset and WordPress.

Then Single Quotes are due to the nested ShortCode which other wise will not work fine.

You can try with "default" double quotes but most probably it will not present the desired result due to the WordPress ShortCode API.

May I ask why you require to call the ShortCode via PHP and do not use Layouts or Content Templates?

You should in this case (PHP) use wpv_do_shortcode, because the native WP do_shortcode will NOT render any nested ShortCodes in any case anymore, since the latest WordPress ShortCodes API changes.
This function is in Views, so it's worth to wrap the function with function_exists in case of disabling it.

Thank you

#358344

Thanks Beda,

The template I am using has quite a bit of php in it for an ACF form - but it seems

cred_delete_post_link(get_the_ID(), '<i class="fa fa-times-circle dash-breadcrumbs-icon"></i><span class="dash-nav-text">Delete</span>', 'delete', 'cred-refresh-after-delete rl-cred-delete', 'display: block;', 'Do you really want to delete this Project? There is no undo.', 'Project Deleted.', 1, '/client/')

This is not working because your dev team didn't fix the code yet:

https://toolset.com/forums/topic/cred-delete-post-php-link-not-working/

If I do the shortcode version, there will be too many quotes for it to work out seeing as using views isn't an option for me. So not too sure what the solution is at this point.

To be fair the advertising for toolset does claim php template compatibility for developers.

#358430

That ticket is marked as resolved, our DEV team wont get any notification on resolved tickets follow ups.

I have advised them to look again into this issue.

As for the ShortCode Quotes problem, we deal with a WordPress restriction here and not toolset.
WordPress does not want any ShortCodes populating HTML or other ShortCodes, and that is why we use our own function instead of do_shortcode.

Also that is why you sometimes need to use single Quotes instead of the default double quotes.

We can not change that, it's a WordPress restriction.

If Views is not a option for you the above Code provided by me wont work anyway as it uses a Views ShortCode.
([wpv-post-id id='$general-parent'])

That Code I provided requires View to be active, but you don't need to use a Content template or View to use that code, as I mentioned, you can simply insert it also directly to the WP Editor for the Child Post

To achieve your goal "redirecting to parent post after successful custom post deletion." with PHP CRED API you could use the code below but as you correctly state, that is not working and I reported that to the DEV:

<?php 
  echo 
    cred_delete_post_link(
        '76', //ID to delete
        'text', 
        'delete', 
        'class', 'style', 
        'message', 
        'message2', 
        '0',
        '44' //ID to redirect to
)?>

I also requested a update of our DOC for the PHP snippet here:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred-delete-post-link

Please expect my informations here in the forum.

Thank you for your patience.

#359057

Hi Beda,

Did you try a shortcode with redirect? For some reason even if I put redirect="/clients" in the cred_delete_post_link shortcode, the page doesn't redirect when the post is deleted.

Please let me know - I'm using the current beta version for CRED

#359058

Otherwise the shortcode seems to be doing its job

#360349

Our CRED DEV discovered a issue with the API and is working on a fix.

I have to apologize that I can not provide a fix for the PHP myself in the moment and have to wait myself for the DEV Team to update me (and the API)

As soon I have news, you will hear them straight away.

Thank you for your patience.

#361977

We updated the Code and it's DOC.
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred-delete-post-link

Please have a look, it elaborates as per our requirements and should work fine, at least it did on local tests.

Please don't hesitate to inform me in case the issue persists and let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

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