Support

Account

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

Solving

How to show posts by field date picker

  • Hey! I am creating a page that shows peoples namedays. I have created field group(name days) by date (date picker) and name (text)

    I also use Elementor.

    I also have created few example posts via the new item that was automatically created to my wp sidebar (namedays) and inserted there topic, name and date.

    How I can show on my homepage namedays only by todays date? So that when I have created namedays for every single date of the year, my ”posts” would only show the posts that have todays date?

  • Please provide more information on your field group and field hierarchy.

  • Hey!

    I have deleted all as what I tryed didnt work so there no fields rn.

    So my issue is how to get data if I create Field Group Labels:

    Field Group: Namedays

    Labels:
    Date (date picker)
    Name (text)

    With these I can create a nameday post.

    Now on my homepage, I would need to get data from that “Date” so that it shows only the posts that have todays date on it. By that way the post (someones dayname) appears on my homepage.

    How to do this? If this makes sense to you, please let me know step by step guide as I havent used ACF before.

    Note: I use Elementor, and If I now set Elementor widget to show “nameday” posts, it will show all of them. It should only show the posts that has todays date on them.

  • This would require creating custom queries and custom templates for Elementor. You will need to contact elementor, you will probably need elementor pro or some other plugin that allows you to create custom queries and post loops for elementor. This is not something you’ll find help with on this forum.

    The only thing that I can do it point you do how to do queries on posts by an ACF date field. This topic has been covered many times on this forum.
    [FORUM SEARCH RESULTS]

  • 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, Hello theme

  • 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

  • How I can show on my homepage namedays only by todays date? So that when I have created namedays for every single date of the year, my ”posts” would only show the posts that have todays date?

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

You must be logged in to reply to this topic.