Custom multicheck with options_cb
-
Hello,
I am working with your awesome plugin. I am not so expert with PHP and wordpress and I want to ask you something:
I created this new metabox with the options_cb
function cmb2_guide() { $prefix = '_cmb_'; $cmb = new_cmb2_box( array( 'id' => 'categorie_guide_box', 'title' => __( 'Categorie Guide', 'cmb2' ), 'object_types' => array( 'guide_products', ), // Post type 'context' => 'side', 'priority' => 'low', 'show_names' => true, ) ); $cmb->add_field( array( 'id' => $prefix . 'categorie_guide', 'type' => 'multicheck', 'options_cb' => 'get_categorie_catalogo_guide', ) ); }and this is my options_cb function:
function get_categorie_catalogo_guide( $query_args ) { $args = wp_parse_args( $query_args, array( 'post_type' => 'catalogo-guide', 'numberposts' => -1, ) ); $posts = get_posts( $args ); $post_options = array(); if ( $posts ) { foreach ( $posts as $post ) { $post_options[ $post->ID ] = $post->post_title; } } return $post_options; }Now, I have some issues for the front-end part.
Here’s my code in the php page where I need to show the elements:<?php $productCat = $post->post_name; $args = array( 'post_type' => 'guide_products', 'posts_per_page' => 50, 'order' => 'ASC' ); $productQuery = new WP_Query( $args ); ?> <?php if($productQuery->have_posts()) : ?><?php while($productQuery->have_posts()) : $productQuery->the_post(); ?>Now, I need to show all the ‘guide_products’ posts with the $productCat.
I tried to add this option right after ‘order’ but it doesn’t work'meta_query' => array( array( 'key' => '_cmb_categorie_guide', 'value' => $productCat ) ),How should I set it to work correctly?
Thank you so much.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Custom multicheck with options_cb’ is closed to new replies.