Skip Navigation

[Resolved] using cred_delete_post_link in function

This support ticket is created 7 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 7 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#593379

I am trying to:

I am trying to insert a link to delete a post by using cred_delete_post_link in a PHP function. I don't want to echo it because I'm putting all of the output from the function in a string before returning it. How can I build this link in a return string?

I have used this function in table structure and cred_delete_post_link showing delete link on top of the page instead of its coloumn.

#593384

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Could you please share the string code or your function code where you've added CRED delete post link?

#593491

Hi,

Here is the function code :

add_shortcode( 'get_relative_content', 'GetRelativeContent' );
function GetRelativeContent($atts){
global $wpdb;
$posttype = $fields = $editlink = $deletelink = '';
$posttype = $atts['posttype'];
$fields = $atts['fields'];
$editlink = $atts['editlink'];
$deletelink = $atts['deletelink'];
$users = wp_get_current_user();
$user_id = $users->ID;
if(!empty($fields) && strstr($fields, ',', true)){
$fields_arr = explode(',', $fields);
}else{
$fields_arr = array($fields);
}

if(is_array($fields_arr) && count($fields_arr)>0){

for($i=0; $i<count($fields_arr); $i++){
$meta_arr[$fields_arr[$i]] = $fields_arr[$i+1];
$i++;
}
$meta_arr['Action'] = array('edit'=> $editlink, 'deletelink'=> $deletelink);
$data .="<table> <tr>";
foreach($meta_arr as $metakey => $metaname){
$data .="<th> $metakey </th>";
}
$data .="</tr>";
$args = array(
'posts_per_page' => -1,
'post_type' => $posttype,
'author' => $user_id,
);

$posts_arr = get_posts( $args );

if ( $posts_arr ) {
foreach ( $posts_arr as $post ) :
setup_postdata( $post );
$data .="<tr>";
foreach($meta_arr as $metakey => $metaname){
if(is_array($metaname)){
$data .="<td> ID&ptype=$posttype'>Edit ";
$data .=cred_delete_post_link($post->ID, 'Delete', 'delete', 'cred-refresh-after-delete', 'display: block;', 'Do you really want to delete this data?', 'Post Deleted.', 1, 1);
$data .="</td>";
}else{
$data .="<td>". get_post_meta($post->ID, sanitize_text_field($metaname), true)." </td>";
}
}
$data .="</tr>";
endforeach;

wp_reset_postdata();
}
$data .="<tr>";
$data .="";
$data .="</tr> </table>";
}
return $data;
}

#593515

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

The CRED delete post link code you added to place looks OK.

Could you please share problem URL where I can see the issue?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.