Skip Navigation

[Resolved] wpt_field_options filter not triggering

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by igorU 6 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#608932

I am trying to:

Populate a "select" custom field dynamically in Backend using following code:

add_filter( 'wpt_field_options', 'owp_fc_prefix_custom_options', 10, 3);
function owp_fc_prefix_custom_options($options, $title, $type) {
    error_log('triggered');
    switch ($title) {
            case 'Año': 
                $options = array();
                $options[2014] = "2014";
                $options[2015] = "2015";
                $options[2016] = "2016";
                $options[2017] = "2017";
                break;
    }
     return $options;
}

I expected to see "Año" select field populated.

Instead, the field is not populated with any options.

I've tried to log function execution adding "error_log('triggered');" but on my log txt this is not displyed, so it seems that the function is never executed.

What am I doing wrong?

Thanks

#609038

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

Thank you for contacting our support forum.

Actually since this is an undocumented function from within our then its not guaranteed to produce the results that is expected by you.

We cannot assist with this one, however there is a report on our internal site that there is a feature request for something like this where you can populate the types custom field with a hook.

For now there is not much we can do but wait until this request is completed.
Thanks,
Shane

#609327

It's a nonsense this limitation where select custom fields can't be populated dynamically. ACF has this feature since years ago.

Anyway, maybe you have a better solution for my workaround. I have a CPT with a custom field which is a date field. I want to be able to filter this posts with a given year via URL parameter. I tried with an aditional select field where just years are stored buy it is not possible to populate dynamically as you say.

So... is there a way to filter posts in archive using a date custom field with a given year in URL param?

Thanks

#609717

Any help on this? 🙁

#609813

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Igor,

So essentially you want to filter the post by just year using the filters.

Currently you're not able to filter by the year only since the filter is done using the entire timestamp.

If its possible an alternative would be have a set of custom fields one for Day, Year and Month

This way you can select the values individually and you can then filter by a certain year instead of an entire timestamp.

Please let me know if this helps.
Thanks,
Shane

#618692

Not a solution for me. I except you can improve this...