Skip Navigation

[Resolved] Delete a post in a view loop using a button

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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by cesarR 5 months, 1 week ago.

Assisted by: Nigel.

Author
Posts
#2734530

I want to add a button in a view loop to delete the post listed.

I have tried with:

[cred_delete_post_link post="[wpv-post-id]" text="DELETE" action="delete" message_after='Deleted' message_show='1']

[cred_delete_post_link action="trash" text="Delete %TITLE%" message_after="Post deleted" message="Are you sure you want to delete this post?" message_show="1"]

[cred-delete-post type="link" onsuccess="8" action="delete"]

[cred_delete_post_link action="trash"]

Right now the last one above is set, and the link for the button in the form shows this:

/wp-admin/admin-ajax.php?action=cred-ajax-delete-post&cred_post_id=575&cred_action=%22trash%22&redirect=0&_wpnonce=376060bf29%27%20%20id=%27_cred_cred_575_1%27%20target=%27_cred_cred_575_1_iframe%27%20onclick=%27return%20_cred_cred_delete_post_handler(true,%20this,%20false,%20false,%20%22%22,%201);%27%3E%3C/a%3E

But the psot is not deleted and this shows a 404 page.

Thanks for your help.

#2734803

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I just checked on my local test site and inserted the delete shortcode via the Toolset Forms button in a Fields and Text block, and it worked when testing on the front end.

The shortcode generated was

[cred-delete-post action='trash' onsuccess='self']Delete this post[/cred-delete-post]

Based on the options I chose when inserting the shortcode, clicking the Delete button submits a request that results in the post being trashed, and the same page reloading.

The available arguments are described here: https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred-delete-post

Do you want to try the same on your site?

#2735120
loop view.jpg
button.jpg

Thanks, but this does not work on my setup...

I'm using a button in a view loop (please check the included image)

My guess your solution will work on the post view and I'll try it...

But what I really need is the right shortcut to place in a button link to delete the post in the view loop row.

#2735537

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2024-08-30 at 08.23.23.png

My example is in the loop output of a View (screenshot).

The problem on your site, it looks to me like you are adding the shortcode to the link section of a button. If you just add the shortcode to a Shortcode block so that you can inspect the generated output on the front end, you'll see that it outputs an anchor element. The link section of a button would generate an anchor element, so you might be trying to add an anchor element within an anchor element, which would be invalid HTML and would not work.

In which case you would need to use something other than a button block, possibly hand-crafting the HTML to provide the same markup for the button with your link coming from the shortcode.

#2737980

Thanks, like you said, I ended up editing in html view the button block, fomatting it like this:

<div class="tb-button" data-toolset-blocks-button="1">[cred-delete-post action='trash' onsuccess='self' class="tb-button__link"]<i class="tb-button__icon"><span class="tb-button__content"></span>[/cred-delete-post]</div>

Worked fine.

Best Regards.