get_post_meta returns a bool (false) calling post from Ajax

There is a function that fixes the problem of displaying bool (false) when I call get_post_meta with Ajax. Bool (false) display with a var_dump Otherwise I have nothing.

I only get this problem with Ajax. With my single.php the get_post_meta is displayed.

I have no error, just "bool (false)".
Do you know where the problem comes from?

php – WordPress get_post_meta is not working on publishing

I'm using One Signal to set up a notification system for a mobile app on WordPress.

For example, if I post a new post, a notification will be sent to all my application devices.

The problem is that I can not send post_meta with a signal notification because it will return an undefined value the first time you click the Publish button.

But it will work the next time I click on the same post !! So why this delay / behavior?!

Same problem / behavior also at get_field for ACF plugin.

The code of the filter that a signal uses:

add_filter('onesignal_send_notification', 'onesignal_send_notification_filter', 10, 4);

function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
{
    // Change the notification's title, message, and URL
    if($post->post_type == "mobile_notifications"){
        $fields('headings') = array("en" => wp_strip_all_tags($post->post_title));
        $fields('contents') = array("en" => wp_strip_all_tags($post->post_content));

        $fields('data') = array( 'type' => 'product', 'data' => get_post_meta( $post->ID, 'prefix_hash_product' ) );

//            if ( !empty(get_field('target_product', $post->ID)) ) {
//                $fields('data') = array( 'type' => 'product', 'data' => get_field('target_product', $post->ID) );
//            } elseif(!empty(get_field('target_category', $post->ID))) {
//                $fields('data') = array( 'type' => 'category', 'data' => get_field('target_category', $post->ID) );
//            }
    }
    unset($fields('url'));

    return $fields;
}

get_post_meta () does not work for the first post within the loop

I need to add a different custom class to each div in my WordPress loop. I read about it post_class() Function and filter, but I am not sure if it is a good approach to do this. At the moment I have this code and use the get_post_meta() However, to preserve the custom field that I set with the class to be displayed, it only works for the second displayed post. Is there an update or do I need to use it? post_class() instead?

 'home-slider', 'posts_per_page' => 3) ); ?>
have_posts() ): while( $scrollable->have_posts() ): $scrollable->the_post(); ?>
ID,'class',true); ?>
      

Hello

Nice to meet you.

array – get_post_meta () from several contributions

I'm trying to go through all cpt posts and get 3 values ​​with get_post_meta (). I'm getting a multidimensional array where I'm having trouble getting the values ​​I want. I wondered if there is a better way to achieve this.

function leweb_get_events_detail() {

        // Query
        global $wp_query;

        // Arguments  
        $args = array(
            'post_type' => 'events',
        );

        // Start the Query
        $query = new WP_Query( $args );

        // The Loop
        if( $query->have_posts() ) {

            $results = array();

            while( $query->have_posts() ) {

                $query->the_post();

                $event_date_timestamp = get_post_meta( get_the_ID(), 'event_date_timestamp', true );
                $future_timestamp = strtotime("+1 week");

                if( $event_date_timestamp < $future_timestamp ) {

                    $results() = get_post_meta( get_the_ID() );

                }
            }

            return $results;

        }   

        wp_reset_query();

    }

This is what the array looks like: (I shortened it a bit)

Array
(
    (0) => Array
        (
            (event_budget) => Array
                (
                    (0) => Bis € 4000
                )

            (event_date) => Array
                (
                    (0) => 27.10.2019
                )

            (event_date_timestamp) => Array
                (
                    (0) => 1572134400
                )

        )

    (1) => Array
        (
            (event_budget) => Array
                (
                    (0) => Bis € 500
                )

            (event_date) => Array
                (
                    (0) => 29.10.2019
                )

            (event_date_timestamp) => Array
                (
                    (0) => 1572307200
                )

        )

)

post meta – get_post_meta / update_post_meta array

I try to store the ID of the current user (if the user is logged in) in an array with the post_meta key "post_is_read" in every post that the user reads, so that I can perform certain actions, such as: For example, you can mark the post as "unread". ,

I added this single page Template:

$readers = get_post_meta(get_the_ID(), 'post_is_read');
$current_user = wp_get_current_user();
if (!in_array($current_user->ID, $readers)) {
   $readers() = $current_user->ID;
    update_post_meta( get_the_ID(), 'post_is_read', $readers, false);
}

Inside the posts loop, I've added the following code:

$readMeta = get_post_meta( get_the_ID(), 'post_is_read', true );
$current_user = wp_get_current_user();
if ( $readMeta != $current_user->ID ) {
   echo 'unread post';
}

I've tried many variations of the first block of code, add_post_meta, update_post_meta, and so on. One problem I've noticed is that when printing the array stored in the meta-key "post_is_read," the output is just "array." I think this is a big problem if it is not the only one in the code.

get post meta – get_post_meta and add_post_meta do not work

I have a code like below, but he returns it false, There are data in $ggowlccpy_transaction_details_capture and the order number is transferred correctly. This is for Woocommerce Order Meta.

How can I debug this? in phpmyadmin which table should I search for the data

 $ggowlccpy_order_id,
    'transaction_id'  => $ggowlccpy_response('transaction_id'),
    'transaction_tag' => $ggowlccpy_response('transaction_tag'),
    'method'          => $ggowlccpy_response('method'),
    'amount'          => $ggowlccpy_response('amount'),
    'currency_code'   => $ggowlccpy_response('currency'),
    'positionofsave'  => 'captured',
);

update_post_meta(
    $post->ID,
    '_ggowlccpy_trasaction_capture',
    $ggowlccpy_transaction_details_capture
);

add_post_meta(
    $post->ID,
    '_ggowlccpy_refund_details_get',
    base64_encode( serialize( $ggowlccpy_transaction_details_capture ) )
);

$data = get_post_meta(
    $ggowlccpy_order_id,
    $key = '_ggowlccpy_refund_details_get',
    $single = false
);

$tb_meta_unserialized = unserialize( base64_decode( $data ) );

error_log( var_export( $tb_meta_unserialized, 1 ) );

echo $tb_meta_unserialized;

Go through all meta keys with get_post_meta

I'm building a custom solution that requires me to get all the meta values ​​for a post in an array. I have many "keys". Is there a way to go through them all without doing that? I have the post ID in my script at this point.

$ image_meta = get_post_meta ($ post-> ID, & 39; image & # 39 ;, true);

// Auto year

$ car_year = get_post_meta ($ post-> ID, & # 39; car_year & # 39 ;, true);

// car kilometer

$ car_mileage = get_post_meta ($ post-> ID, & car; mileage & # 39 ;, true);

// car price

$ car_price = get_post_meta ($ post-> ID, & # 39; car_price & # 39 ;, true);

// Car Model

$ car_model = get_post_meta ($ post-> ID, # car_model #, true);