Support

Account

Home Forums General Issues How to show posts by field date picker Reply To: How to show posts by field date picker

  • I have Field Group “nimipäivät” (namedays)

    Inside that I have 2 fields

    “nimi” (name) = text
    “päivämäärä” (date) = date picker
    IMAGE:https://ibb.co/Gx8Z7YS

    Also I have Custom post plugin and there is added namedays
    IMAGE: https://ibb.co/6X79X4F

    Group fields post rule is set to nimipäivät IMAGE:https://ibb.co/Gx8Z7YS

    Now I would need to show todays date posts ONLY on my homepage.

    I have this code added to my funtions.php

    function show_todays_name_days() {
    // Hae tämän päivän päivämäärä
    $today = date(‘Ymd’); // Muutettu takaisin Ymd-muotoon

    // Luo uusi WP_Query-objekti
    $args = array(
    ‘post_type’ => ‘nimipaivat’,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘field_65236d64b874e’, // Päivitä tämä kentän avaimellasi
    ‘value’ => $today,
    ‘compare’ => ‘=’
    )
    )
    );

    $query = new WP_Query($args);

    // Tarkista, onko postauksia
    if ($query->have_posts()) {
    while ($query->have_posts()) {
    $query->the_post();
    // Tulosta postauksen otsikko ja sisältö
    echo ‘<h2>’ . get_the_title() . ‘</h2>’;
    echo ‘<div>’ . get_the_content() . ‘</div>’;
    }
    } else {
    // Ei postauksia tälle päivälle
    echo ‘Ei nimipäiviä tänään.’;
    }

    // Palauta alkuperäinen postausdata
    wp_reset_postdata();
    }

    add_shortcode(‘show_todays_name_days’, ‘show_todays_name_days’);

    And I am using this shortcode : [show_todays_name_days]

    But this code doesnt work and I dont know how to show todays date posts on my homepage.

    Using also Elementor with Hello theme