Support Forum
Support › MB Settings Page › How to showcase a bunch of photos from uploading multiple on the settings page?
So I have used this code with custom fields before and I am trying to use the same code with custom fields from a settings page but it isn't working.
<?php
$companylogos = rwmb_meta( 'settings_logos', ['object_type' => 'setting'], 'Company');
foreach ( $companylogos as $companylogo )
$image = RWMB_Image_Field::file_info( $companylogo, array( 'size' => 'company-logo' ) );
{
echo "<img />";
}
?>
Hi,
Can you please share the code that creates the settings page and custom fields on your site? Refer to this documentation to show images from the settings page https://docs.metabox.io/extensions/mb-settings-page/#getting-field-value
So I use the meta box AIO
<?php
add_filter( 'mb_settings_pages', 'your_prefix_function_name' );
function your_prefix_function_name( $settings_pages ) {
$settings_pages[] = [
'menu_title' => __( 'Guru Settings', 'your-text-domain' ),
'option_name' => 'Company',
'position' => 2,
'parent' => 'index.php',
'style' => 'no-boxes',
'columns' => 1,
'icon_url' => 'dashicons-admin-generic',
];
return $settings_pages;
}
AND I copied the code that the plugin gives me to the gallery section. This gallery section custom field was added after I asked you the question above
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
function your_prefix_function_name( $meta_boxes ) {
$prefix = 'settings_';
$meta_boxes[] = [
'title' => __( 'Guru', 'your-text-domain' ),
'id' => 7,
'settings_pages' => ['guru-settings'],
'tabs' => [
'settings_home_page' => [
'label' => 'Home Page',
'icon' => 'admin-home',
],
'settings_contact_info' => [
'label' => 'Contact Info',
'icon' => '',
],
'settings_about_us_page' => [
'label' => 'About Us',
'icon' => 'admin-users',
],
'settings_contact_us' => [
'label' => 'Contact Us',
'icon' => '',
],
'settings_code' => [
'label' => 'Code',
'icon' => '',
],
'settings_mobile_menu' => [
'label' => 'Mobile Menu',
'icon' => 'editor-justify',
],
'settings_coupons' => [
'label' => 'Coupons',
'icon' => 'tag',
],
],
'fields' => [
[
'name' => __( 'Total # of Reviews', 'your-text-domain' ),
'id' => $prefix . 'total_reviews',
'type' => 'text',
'tab' => 'settings_home_page',
],
[
'name' => __( 'AVG Stars', 'your-text-domain' ),
'id' => $prefix . 'avg_stars',
'type' => 'text',
'tab' => 'settings_home_page',
],
[
'name' => __( 'Promise Title', 'your-text-domain' ),
'id' => $prefix . 'promise_title',
'type' => 'text',
'sanitize_callback' => 'none',
'tab' => 'settings_home_page',
],
[
'type' => 'heading',
'name' => __( 'Picture Gallery', 'your-text-domain' ),
'tab' => 'settings_home_page',
],
[
'name' => __( 'Actrivate Gallery', 'your-text-domain' ),
'id' => $prefix . 'activate_gallery',
'type' => 'switch',
'style' => 'rounded',
'tab' => 'settings_home_page',
],
[
'name' => __( 'Gallery Title', 'your-text-domain' ),
'id' => $prefix . 'gallery_title',
'type' => 'text',
'tab' => 'settings_home_page',
],
[
'name' => __( 'Gallery Explanation', 'your-text-domain' ),
'id' => $prefix . 'gallery_explanation',
'type' => 'wysiwyg',
'tab' => 'settings_home_page',
],
[
'name' => __( 'Gallery Pictures', 'your-text-domain' ),
'id' => $prefix . 'gallery_pictures',
'type' => 'image_advanced',
'image_size' => 'large',
'tab' => 'settings_home_page',
],
Hi,
I do not see the field with ID logos
in your code. Can you please try to use the image_advanced
field with ID gallery_pictures
?
The helper function should be
$companylogos = rwmb_meta( 'settings_gallery_pictures', ['object_type' => 'setting'], 'Company');