How to Create Custom Lable for listing?

Hello Good morning,
first of all, Thank you so much. you made a great theme and plugin. appreciate it.
I want to add a Custome label to my list block and listing. I have listings like events where I have start dates & end Date Attributes. Now I want Custome Lable according to the current date Which tells the event status which is Upcoming, Live, and Expired. is it possible to do that automatically? based on the date?

Hi,

Thank you for the kind words.

Yes, it is possible, but it requires a custom implementation. If you are familiar with WordPress customization or have a developer who can set this up, we recommend overwriting the template parts and adding the appropriate code there. Please check this doc How to override template parts - HivePress Help Center

​I hope this is helpful to you.

I tried this PHP snippet but it’s not working can you please help to correct it?

/**
 * Custom function to update listing attributes based on date conditions.
 */
 public function update_attribute( $attribute_id ) {
    // Get the start date, end date, and current date
    $start_date = get_post_meta($attribute_id, 'hp-listing__attribute--start_date', true);
    $end_date = get_post_meta($attribute_id, 'hp-listing__attribute--end_date', true);
    $current_date = current_time('timestamp');

    // Set default values for attributes
    $offer_attribute = 'UPCOMING';
    $live_attribute = 'hp-listing__attribute--upcoming';
    $upcoming_attribute = 'hp-listing__attribute--live';
    $expire_attribute = 'hp-listing__attribute--expire';

    // Check conditions and update attributes accordingly
    if ($current_date < $start_date) {
        $offer_attribute = 'UPCOMING';
        $live_attribute = 'hp-listing__attribute--upcoming';
        $upcoming_attribute = 'hp-listing__attribute--live';
        $expire_attribute = 'hp-listing__attribute--expire';
    } elseif ($current_date >= $start_date && $current_date <= $end_date) {
        $offer_attribute = 'LIVE';
        $live_attribute = 'hp-listing__attribute--live';
        $upcoming_attribute = 'hp-listing__attribute--upcoming';
        $expire_attribute = 'hp-listing__attribute--expire';
    } elseif ($current_date > $end_date) {
        $offer_attribute = 'EXPIRED';
        $live_attribute = 'hp-listing__attribute--expire';
        $upcoming_attribute = 'hp-listing__attribute--upcoming';
        $expire_attribute = 'hp-listing__attribute--live';
    }

    // Update the offer attribute value
    update_post_meta($attribute_id, 'hp-listing__attribute--offer', $offer_attribute);

    // Update the live attribute
    update_post_meta($attribute_id, 'hp-listing__attribute--live', $live_attribute);

    // Update the upcoming attribute
    update_post_meta($attribute_id, 'hp-listing__attribute--upcoming', $upcoming_attribute);

    // Update the expire attribute
    update_post_meta($attribute_id, 'hp-listing__attribute--expire', $expire_attribute);
}

// Hook the function to save_post to update attributes when a listing is saved
add_action('save_post', 'update_listing_attributes_based_on_date');

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.