WordPress.org

Forums

Advanced Custom Fields
Do something after click on the checkbox field of custom post type. (4 posts)

  1. danielffr
    Member
    Posted 1 year ago #

    Hello,
    I am building an website for displaying products. I have the custom post type "products" and this post has many custom fields, one is a checkbox with only one possible choice. This checkbox is there to allow the product to display in front page as a featured product. I need to have only one product with that checkbox checked. To prevent that more than one hava that checkbox checked is there a way to when we check that checkbox field, uncheck the same checkbox field in the others products?

    I hope that i made myself clear.

    Thanks in advance!

    http://wordpress.org/plugins/advanced-custom-fields/

  2. domokun
    Member
    Posted 1 year ago #

    Your question makes sense, but I don't believe thats possible.

    I would suggest that you alter the wp_query on your homepage to only pull back a single, latest post.

  3. dantahoua
    Member
    Posted 8 months ago #

    Hello,
    did you fid a way of doing this? I would like to do the same (using ACF or not).

  4. lagdonkey
    Member
    Posted 8 months ago #

    Well, acf has a save filter. So my suggestion would be to use that hook, and when you save, check for the checkbox. If it's checked, then do a call to all posts that have that checkbox saved, and then unsave them. It could end up being quite a heavy query, if you have a lot of posts, but it's possible.

    So to clarify:

    Use ACF's pre-save filter.

    $query = new wp_query('meta_field_where_checkbox_is_stored);

    $while $query->has_posts unset meta_field_where_checkbox_is_stored;

    Obviously that's not working code, but just an idea.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags