Skip Navigation

[Résolu] CRED editing posts

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.

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

Last updated by Adriano Il y a 8 années et 1 mois.

Assigned support staff: Adriano.

Auteur
Publications
#154012

Hi,

I would like to achive something like this.

SETUP:

I have a list of posts. I want to use CRED to frontend editing of posts from list.
I have created a form with CRED. It has everything to accomplish post edition.
Also I have a page, where I want to display form for editing posts. Page template is created in php file, but since CRED forms can be inserted in php it's not a problem.

WHAT I NEED:

I would like to add an edit link for every post on my list. After clicking this link I want to show page with a form, where user will be able to edit post content. I don't want to show post with a form, but my page with a form. Page is always the same, but form data depends on clicked link.

How to do it?

#154490

Dear dariuszP,

It would be possible, but I found a bug on our [cred_form] shortcode, which doesn't allow to add custom shortcodes in the "post" parameter. I added a to do list to fix it and released in a next patch.

For now you just can customize the single.php file, the forms are renderized there. Is there anything else I can help you?

#156373

I see that I will have to create my own form.
One more thing, how to populate image field created with Types using php ?
I want all defined image sizes to be created.

Will passing a link to original file be enaugh, or maybe I should use wp_insert_attachment (for creating all image sizes) and then pass the id of newly created attachment ?

#156478

Dear dariuszP,

Image field is a custom field stored in post_meta table, so you can use update_post_meta function to store some data there:

update_post_meta($post_id, 'wpcf-image', '<em><u>hidden link</u></em>');

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#157060

The code you have posted will put a link to a field associated with post. But will it create all image sizes based on original image in the link?

#157204

Dear dariuszP,

You are right, in this case you will need to use wp_insert_attachment (http://codex.wordpress.org/Function_Reference/wp_insert_attachment). You can use CRED API (https://toolset.com/documentation/user-guides/cred-api/) to get the current post ID and save it on wp_insert_attachment. Using the cred_save_data hook you can get the post ID by the variable $post_id.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#157436

I will be using my own form without CRED. So after I use wp_insert_attachment, what should I pass to the image field from Types? Link to original image or attachment id maybe?

#157714

Dear dariuszP,

I'm thinking and testing about it on my localhost and I can see that actually you don't need to create different sizes. Types store just the URL of the image, and it is resized using Types GUI on front end. The other images with different sizes only are created when you use the WordPress library which is not your case (storing value by php code).

See Types shortcode documentation for images, which will resize your saved image: https://toolset.com/documentation/functions/#tf-145214

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#157718

No, it is not like that. When you add an image field to a post, and then fill it at backend in admin panel, all image sizes are created. Attachment assign to a post is created also.
Finally when you want to display url from image field using php, you can pass the argument to a function containing desired size. And returned url will appropriate for selected image size (not original image).

So my question still stands.

#157739

Dear dariuszP,

You are right, but these extra images with different sizes are created using the wordpress library feature (Types and CRED also use it to save images), but you can not do that with php code as you want. I talked with our Types developer, and in this case you just can store the URL of the image and let the Types GUI show the different sizes by parameters.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#157743

Aa I wrote earlier, I want to use wp_insert_attachment. Will assigning my attachment to post, and putting url to the original file inside Image Types field, give me the ability to use render function with size parameter?

#157762

Dear dariuszP,

Right, I'm assuming that already have uploaded the image (in the default wordpress upload folder) and just need to create the attachment and store the URL in the custom field. In this case the code below should works:

    $wp_filetype = TYPE OF THE IMAGE;
    $filename = NAME OF THE FILE;
    $wp_upload_dir = wp_upload_dir();
    $attachment = array(
        'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
        'post_mime_type' => $wp_filetype,
        'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
        'post_content' => '',
        'post_status' => 'inherit'
    );
   $attach_id = wp_insert_attachment( $attachment, $filename);
   update_post_meta( $post_id, 'wpcf-custom_image_field', $wp_upload_dir['url'] . '/' . basename( $filename ) );

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#157771

Ok, thanks for your help

#157815

You are welcome.