Skip Navigation

[Résolu] Update repeatable field's post date as parent post date

This support ticket is created Il y a 2 années et 5 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

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

Last updated by Luo Yang Il y a 2 années et 5 mois.

Assisted by: Luo Yang.

Auteur
Publications
#2215331

Dear Sir/Madam,

I understand the repeatable field is saved as like as a child post in database, how can I update the repeatable filed's post date same as the parent post date?

I have a custom post type invoice which contain repeatable field "product", I will update the repeatable field when save as below

function my_save_data_action($post_id, $form_data)
{
    
    if ($form_data['id']==101) {
        $items = explode("|", $_POST['product-select']);
        wp_update_post( array(
            'ID' => $post_id,
            'post_name' => $post_id,
            'post_title' => sprintf("%s - %s", $items[2], $items[1]),
            'post_date' => ( same as parent invoice date )
        ));
        update_post_meta( $post_id, 'wpcf-item-description', $items[1]);
        update_post_meta( $post_id, 'wpcf-item-sku', $items[2]);
        update_post_meta( $post_id, 'wpcf-item-amount', $_POST['wpcf-item-quantity'] * $items[3]);
    }
}

How can I get the invoice date when I update the post_date?

Best regards,

Kelvin.

#2216447

Hello,

Please elaborate the questions with more details:
When do you want to update the repeatable field's post?
After save the " invoice" post? or after save the "product" item?

#2219093

Dear Luo Yang,

I want to save the "product" item but copy the post date of the invoice.

Best regards,

Kelvin.

#2219155

After save child "product" item post, in your custom PHP codes, you can get the parent "invoice" post ID:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
And get the "invoice" post custom date field value:
https://developer.wordpress.org/reference/functions/get_post_meta/
And save it into "invoice" post:
https://developer.wordpress.org/reference/functions/update_post_meta/

#2219163
Screenshot 2021-11-12 at 3.57.59 PM.png

Dear Luo Yang,

I refer to the sampel code

$writer = toolset_get_related_post( $book_id, array( 'writer', 'book' ) );

What is the $relationship between the invoice and product? Refer to my screenshot, additional-item is the product.

After I can update the date of the product record same as the invoice month, how can I query all products that belong to the same date, the query may cross around several invoices

For example
Invoice 001 (Date 1-May-2021)
Product A x 3
Product B x 6
Product C x 2

Invoice 002 (Date 5-May-2021)
Product A x 7
Product C x 3

I want to make a View to list all products make in the invoice in May, the result should be
Sales in May 2021
Product A = 10
Product B = 6
Product C = 5

How can I make this view report?

#2219167

I assume you are going to do it in your custom PHP codes, you can use WP built-in class WP_Query to query products posts, and filter the result by your custom date field, and get the all products that belong to the same date:
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

#2219217
Screenshot 2021-11-12 at 3.57.59 PM.png

Two questions:

1. Can do it with View?

2. Before your answer, sorry I did edit the reply. I refer to the sample code

$writer = toolset_get_related_post( $book_id, array( 'writer', 'book' ) );

I try

$inv_id = toolset_get_related_post( $post_id, array( 'invoice', 'additional-items' ) ); 

but I get the inv_id is 0

What is the $relationship between the invoice and product? Refer to my screenshot, additional-item is the product.

#2220859

The relationship slug is same as your repeatable field group slug: additional-items

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