Home › Forums › Front End PM PRO › Find Messages in Query and then Update Meta
- This topic has 5 replies, 2 voices, and was last updated 5 years ago by David.
- AuthorPosts
- November 23, 2020 at 4:17 am #41850DavidParticipant
Hi Shamim,
I want to do something like the following:
$mgs = fep_get_messages( $args );
if ( $mgs ) {
foreach ( $mgs as $mg ) {
fep_update_meta( $mg->mgs_id, ‘parent_total’, ‘newupdate’ );
}
}I have $mgs for my query but it will not update the meta for each $mg. Am I doing something wrong here? Is it possible?
November 23, 2020 at 4:19 am #41853DavidParticipantIt is using fep_action_message_after_send
November 23, 2020 at 12:12 pm #41858Shamim HasanKeymasterYour code seems ok.
If not working you need more debug code for each line and see upto which line it is working correctly.November 23, 2020 at 4:05 pm #41863DavidParticipantHere is the full code:
$busman = fep_get_meta( fep_get_parent_id(fep_get_the_id()), ‘cus_fep_business’, true );
$args = array(
‘mgs_type’ => ‘message’,
‘mgs_status’ => ‘publish’,
‘mgs_parent’ => 0,
‘per_page’ => 10,
‘fields’ => [ ‘mgs_id’, ‘mgs_title’ ],
‘participant_query’ =>
[
[
‘mgs_participant’ => $busman,
],
],
‘meta_query’ =>
[
[
‘key’ => ‘cus_fep_update’,
‘value’ => ‘driverupdate’,
],
],
);$mgs = fep_get_messages( $args );
if ( $mgs ) {
foreach ( $mgs as $mg ) {
fep_update_meta( $mg->mgs_id, ‘test_meta’, ‘test’ );
}
}
wp_reset_query();If I add this code into the page and load it as normal, all of the messages update with the new meta. However, if I add this code into add_action( ‘fep_action_message_after_send’, function( $message_id, $message, $new_message ){ it does not work. That action is working ok for all the other meta that is being added and updated in it.
Debugging is something that is beyond my skill set at the moment but I will look into it. Any other ideas you have would be appreciated.
November 24, 2020 at 12:32 am #41869Shamim HasanKeymasterfep_get_the_id()is a template function which does not return any value outside loop. So usingfep_action_message_after_sendhook does not give you correct message id.
If you need to usefep_action_message_after_sendhook you can use$message_idvariable instead offep_get_the_id()November 24, 2020 at 12:45 am #41871DavidParticipantOh man, I have fallen to that one before and I didn’t even spot it…
Ok, now it works. I really appreciate your help!!
Thank you!
- AuthorPosts
You need to purchase ‘Front End PM PRO’ to create topic in this support forum.
If you already purchased ‘Front End PM PRO’ please LOGIN.