[Resolved] Notification if field of any child post is more than X
This support ticket is created 2 years, 3 months 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.
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.
So, what I have done so far is to create a view that lists the prices of all items on the current requisiton.
I have a form that is just a button that submits the requisition for approval. I currently have some php code that updates a status field on submission of that form. I could add some more code for that form that loops through the list of prices and checks if any is above the set value, and if so then the notification will fire.
You're setting the relationship on the form ? Or is it a case where you're editing the Child post and you want to send a notification if the field value changes.
The code you are looking at above will only loop through the current post being viewed fields, not the child post fields. Also it gets more complex if the post has many child posts.
It might be easiest if you login and look at the site.
There may be more than one way to do this.
There is a parent post type and a child post type. The children post types are all created by a form embedded in the content of the parent. There is also a view that displays the children embedded in the template of the parent.
Then there is a form that 'finalizes' the parent. My thought is that the form that finalizes the parent could have a field that is set conditionally if a child item has a value higher than a certain number in a particular field.
I know this requires working with the API. I need help doing that. I can get there, but I need help doing so. I don't have a budget for hiring a contractor.
Here's where I'm at so far:
// get child posts of current post
$args = array(
'post_type' => 'req-item',
'post_status' => 'publish',
'numberposts' => -1,
'meta_key' => '_wpcf_belongs_requisition_id',
'meta_value' => get_the_ID()
);
$child_posts = get_posts( $args );
$tests = get_post_meta('wpcf-special-item-price');
foreach ((array)$tests as $test) {
echo $test . '<br />';
}
I know this is missing a few pieces, and i think the wpcf_belongs_ thing is deprecated but, again, this is why i need help.
But i'm assuming here that you will be editing the Child post and you only want to send the notification if a value for the repeating field is below/greater than X.
What i'm unsure of is if the form you're using is being used to edit the Child or the Parent post and are those fields that should trigger the notification on the form itself.
Shane has been moved to a different department, so I'll follow up on this ticket.
Please take your time; this ticket will stay open for a couple of weeks. Even if it gets closed and you have some follow-up questions, you can start a new one and include the link to this ticket and we'll have the background info.
I haven't had a ton of time to focus on this, but here's what I have put together so far.
I have not idea if the loop works correctly, or how to check if it is. I also need help with getting the notification to fire if 'wpcf-special-item-price' is greater than 999.
elseif ($form_data['id']==116)//---------------------------------Actions on submit for approval
{
update_post_meta($post_id, 'wpcf-status', 'Pending');
update_post_meta($post_id, 'wpcf-date-submitted', $now);
$origin_id = $atts['child'];
$relationship_slug = 'requisition-to-item';
$child_posts = toolset_get_related_posts(
$origin_id, // get posts connected to this one
$relationship_slug, // in this relationship
array(
'query_by_role' => 'parent', // origin post role
'role_to_return' => 'child', // role of posts to return
'return' => 'post_id', // return array of IDs (post_id) or post objects (post_object)
'limit' => 999, // max number of results
'offset' => 0, // starting from
'orderby' => 'title',
'order' => 'ASC',
'need_found_rows' => false, // also return count of results
'args' => null // for adding meta queries etc.
)
);
foreach ($child_posts as &$value) {
$cost == 'wpcf-special-item-price';
if($cost >= 999){
//fire price notification to business manager
};
}
}
Thank you for any help. I'm still in a place where this isn't my top focus, but it is something I need to get done at some point.
The logic of the code that you've shared and what you've discussed so far with Shane makes sense and it shouldn't be too complicated to achieve through some custom code.
When your form to submit the final requisition post (parent) is ready, can you please share temporary admin login details, along with the link to the page with that form?
I'll be in a better position to suggest some more specific pointers, accordingly.
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.