Find Messages in Query and then Update Meta


Home Forums Front End PM PRO Find Messages in Query and then Update Meta

This topic is: Not Resolved
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #41850
    David
    Participant

    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?

    #41853
    David
    Participant

    It is using fep_action_message_after_send

    #41858
    shamim
    Keymaster

    Your code seems ok.
    If not working you need more debug code for each line and see upto which line it is working correctly.

    #41863
    David
    Participant

    Here 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.

    #41869
    shamim
    Keymaster

    fep_get_the_id() is a template function which does not return any value outside loop. So using fep_action_message_after_send hook does not give you correct message id.
    If you need to use fep_action_message_after_send hook you can use $message_id variable instead of fep_get_the_id()

    #41871
    David
    Participant

    Oh 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!

Viewing 6 posts - 1 through 6 (of 6 total)

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.