• antoniomartoni

    (@antoniomartoni)


    Hello Everyone,

    I’m facing an issue with the restrict_manage_posts hook, which I’m using to build a dropdown filter for filtering posts. (the problem is the same as this previous unanswered post)

    I’m trying both acf_get_field and get_field_object to retrieve the field choices. This works perfectly when the page initially loads, but the data becomes empty when the filter is applied.

    It seems to be related to how restrict_manage_posts works, as it appears to be triggered before ACF data is loaded.

    Does anyone have any advice or documentation on implementing custom filters in the WordPress admin, with ACF values / choices?

    and the text version :

    function mytheme_filter_posts_declare_dropdowns()
    {
    // [.. Vericications de base]

    // Les données sont correctement retournées au chargement initial de la page (lorsqu’aucun filtre n’est appliqué),
    // mais elles sont vides lorsque le filtre est activé.
    $mdp_status_datas_object = get_field_object("mdp_status");
    $mdp_status_datas = acf_get_field("mdp_status");

    // [.. Boucle foreach et construction d'un dropdown]
    }

    add_action('restrict_manage_posts', 'mytheme_filter_posts_declare_dropdowns');

    function filter_posts_by_custom_datas($query)
    {
    // [.. Vericications de base]

    if (!empty($_GET['mdpstatus'])) {
    $query->set('meta_query', [
    [
    'key' => 'mdp_status',
    'value' => $_GET['mdpstatus'],
    'compare' => '='
    ]
    ]);
    }
    }

    add_action('pre_get_posts', 'filter_posts_by_custom_datas');


  • You must be logged in to reply to this topic.