Support

Account

Home Forums ACF PRO Save user input values per ACF post. Reply To: Save user input values per ACF post.

  • I don’t understand where you ‘show’ the offers and how the users should ‘archive’ them. Is offer(s) a custom post type ?

    For my explanation I assume it is (because to me that would be the most logical solution). If it is, I wouldn’t use an ACF form for this because this sounds like a simple user meta storage to me.

    What you want (afaik) is exclude certain (post ids) from showing to the user.
    The ‘goal’ is then to store which ids need to be excluded for each user.

    You would need to create a page which has a form where a user can select which orders/posts have to be excluded.

    The code below needs to ‘go’ into the page which has the form (where users can exclude it).

    if ( isset( $_POST[ 'order_form_nonce' ] ) ) {
    
        if ( ! wp_verify_nonce( $_POST[ "archive_order_nonce" ], 'archive-order-nonce' ) ) {
            // not verified, so return and do nothing
            return;
        } else {
            $offers = ( isset( $_POST[ 'offers' ] ) ) ? $_POST[ 'offers' ] : false;
            if ( is_array( $offers ) && count( $offers ) > 0 ) {
                foreach( $offers as $offer_id ) {
                    $offers_to_archive[] = $offer_id;
                }
                update_user_meta( get_current_user_id(), 'offers_to_archive', $offers_to_archive );
            }
        }
    }
    
    $offer_args = array(
        'post_type'      => 'offer',
        'posts_per_page' => -1,
    );
    $get_offers = get_posts( $offer_args );
    
    if ( $get_offers ) {
        ?>
        <form name="archive_orders" action="" method="post">
            <input type="hidden" name="archive_order_nonce" value="<?php echo wp_create_nonce( 'archive-order-nonce' ); ?>">
            <?php foreach( $get_offers as $offer ) { ?>
                <input name="offers[]" id="offers" type="checkbox" value="<?php echo $offer->ID; ?>" /> <?php echo $offer->post_title; ?>
            <?php } ?>
            <input type="submit" class="button" value="<?php esc_html_e( 'Save', 'text-domain' ); ?>" />
        </form>
        <?php
    }

    Then you can use a simple exclude query to exclude the post ids which are stored by the user.

    $hide_offers_user = get_user_meta( get_current_user_id(), 'offers_to_archive', 1 );

    And then extend your query with this:

    'post__not_in' => $hide_offers

    Hope that helps…