Support

Account

Home Forums Backend Issues (wp-admin) Filter by meta_query

Unread

Filter by meta_query

  • Good day
    please tell me the solution
    There is a custom post type “Games”
    There is a filter by the number of possible players in this game
    In the “Game” itself, the number of players is indicated in the form of an arbitrary field ACF Checkbox
    to 1 to 8 and returns an array accordingly
    Filtering happens through AJAX
    man indicates count. players and you need to load the game in which one of the values
    https://skr.sh/sCV3DSD4zvl
    https://skr.sh/sCV4aBqG37C
    Here is the code for the upload function
    please tell me what should be specified in meta_query for such filtering

        $args = [
        'post_type' => $_POST['postType'],
        'orderby' => 'menu_order',
        'order' => 'ASC',
        'paged' => get_query_var( 'paged' ),
    ];
    
    if( isset( $_POST['playerID'] )) {
        
        $playerID = $_POST['playerID'];
    
        if ( $playerID == 'all' ) {
            $args['meta_query'] = [[]];
        } else {
            $args['meta_query'] = [
                'relation' => 'OR',
                [
                    'key' => 'g__players',
                    'value' => $playerID,
                    'compare' => 'IN'
                ],
            ];
        }
    }
    
    $query = new WP_Query( $args );
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.