Show data on front end problems.

Support MB Conditional Logic Show data on front end problems.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2317
    qbanglaqbangla
    Participant

    Please open this ticket :
    https://support.metabox.io/topic/show-meta-box-data-on-theme/

    My code :

    add_filter( 'rwmb_meta_boxes', 'Brands_and_Products' );
    function Brands_and_Products( $meta_boxes )
    {
    	$meta_boxes[] = array(
    		'id' => 'brand_product',
    		'title' => 'Brands and Products',
    		'post_types' => array( 'post', 'page' ),
    		'context'	=> 'normal',
    		'priority'	=> 'high',
    		// Conditional Logic can be applied to Meta Box
    		// In this example: Show this Meta Box by default. Hide it when post format is aside
    		'hidden' => array( 'post_format', 'aside' ),
    		'fields' => array(
    			array(
    				'id'	=> 'brand',
    				'name'	=> 'Brand',
    				'desc'	=> 'Pick Your Favourite Brand',
    				'type'	=> 'select',
    				'options' => array(
    					'Samsung' 		=> 'Samsung',
    					'Nokia' 		=> 'Nokia',
    					'Symphone' 	=> 'Symphone',
    					'Microsoft' 	=> 'Microsoft',
    					'HTC' 		=> 'HTC',
    					'Sony' 		=> 'Sony',
    					'Huawei' 	=> 'Huawei'
    				)
    			),
    			array(
    				'id' 	=> 'Samsung_products',
    				'name'	=> 'Which Apple product that you love?',
    				'type'	=> 'radio',
    				'options' => array(
    					'Samsung galaxy S' 	=> 'Samsung galaxy S',
    					'Samsung pop'		=> 'Samsung pop',
    				),
    				'hidden' => array( 'brand', '!=', 'Samsung' )
    			),
          array(
    				'id' 	=> 'Nokia_products',
    				'name'	=> 'Which Apple product that you love?',
    				'type'	=> 'radio',
    				'options' => array(
    					'Lumia' 	=> 'Lumia',
    					'N Series'	=> 'N Series'
    				),
    				'hidden' => array( 'brand', '!=', 'Nokia' )
    			),
    		)
    	);
    	return $meta_boxes;
      }

    And to show my data on front end

    
    // Brand
    echo rwmb_meta( 'brand' );
    
    // Samsumg Products
    echo rwmb_meta( 'Samsung_products' );
    echo rwmb_meta( 'Nokia_products' );
    // ...
    

    Brand is showing properly. Which one I've selected about brand - OK,
    I am selection nokia as a brand and Lumia as model. Here - nokia is showing, but lumais not showing properly. If I change the brand to samsung and model - Samsung Galaxy - Samsung is showing, but model - Lumia and Samsung Galaxy both are showing.

    I need to show brand under on model only which I've selected.

    Thanks in advance.

    #2347
    qbanglaqbangla
    Participant

    Is there any answer please ?

    #2350
    Anh TranAnh Tran
    Keymaster

    Sorry for late reply. The last couples of days I had to deal with the bugs in the update of 4.8.1 version.

    Back to your question, are you asking about the condition to show options in the admin area? e.g. If you select Samsung as the brand, then only show Samsung's model. If select Nokia as the brand, show only Nokia's model?

    If that's the correct question, then I see you're doing it right. I tested your code and see it works perfectly.

    Regarding showing the value on the frontend, I think you to show only the model if the corrected brand is selected (e.g. only show Lumia if Nokia is selected), you should change the code to this:

    $brand = rwmb_meta( 'brand' );
    echo 'Brand: ', $brand, '<br>';
    $model = 'Samsung' == $brand ? rwmb_meta( 'Samsung_products' ) : rwmb_meta( 'Nokia_products' );
    echo 'Model: ', $model;
Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Show data on front end problems.’ is closed to new replies.