Tagged: group field, image
- This topic has 6 replies, 2 voices, and was last updated 1 year, 7 months ago by
Steve.
-
AuthorPosts
-
-
July 5, 2020 at 11:51 pm #10714
rashedul007ParticipantI want to show attachment like section. For this my code for meta field and out is given below:
Meta field Code:<?php /** * Title: Chef Settings * Post Type: section * Order: 20 */ piklist('field', array( 'type' => 'group', 'field' => 'meal_chef', // removing this parameter saves all fields as separate meta 'label' => __('Chef', 'meal'), 'list' => false, 'add_more' => true, 'fields' => array( array( 'type' => 'text', 'field' => 'name', 'label' => __('Name', 'meal'), ), array( 'type' => 'file', 'field' => 'chef_image', 'label' => __('Image', 'meal'), 'options' => array( 'button' => __('Add Image', 'meal') ) ), array( 'type' => 'text', 'field' => 'title', 'label' => __('Title', 'meal'), ), array( 'type' => 'textarea', 'field' => 'bio', 'label' => __('bio', 'meal'), ), array( 'field' => 'social_profiles', 'type' => 'group', 'label' => __('Social Profiles', 'meal'), 'fields' => array( array( 'field' => 'facebook', 'type' => 'text', 'label' => __('Facebook', 'meal'), ), array( 'field' => 'twitter', 'type' => 'text', 'label' => __('Twitter', 'meal'), ), array( 'field' => 'instagram', 'type' => 'text', 'label' => __('Instagram', 'meal'), ), ), ), ) )); <strong>Output code:</strong><?php
global $section_id;
$meal_section = get_post($section_id);
$meal_section_title = $meal_section->post_title;
$meal_section_description = $meal_section->post_content;
?><div class=”section bg-white” data-aos=”fade-up”>
<div class=”container”>
<div class=”row mb-5″>
<div class=”col-md-12 section-heading text-center”>
<h2 class=”heading mb-5″>
<?php echo esc_html($meal_section_title); ?>
</h2>
<?php
echo apply_filters(‘the_content’, $meal_section_description);
?>
</div>
</div>
<?php
$meal_chefs = get_post_meta($section_id, ‘meal_chef’, true);
print_r($meal_chefs);
if ($meal_chefs) :
?>
<div class=”row”>
<?php
foreach ($meal_chefs as $meal_chef) :$meal_chef_image = wp_get_attachment_image_src($meal_chef[‘chef_image’], ‘medium’);
?>
<div class=”col-md-6 pl-md-5 text-center mb-5″>
<div class=”ftco-38″>
<div class=”ftco-38-img”>
<div class=”ftco-38-header”>
”
alt=”<?php echo esc_attr($meal_chef[‘name’]) ?>”>
<h3 class=”ftco-38-heading”><?php echo esc_attr($meal_chef[‘name’]) ?></h3>
<p class=”ftco-38-subheading”><?php echo esc_attr($meal_chef[‘title’]) ?></p>
</div>
<div class=”ftco-38-body”>
<?php echo apply_filters(‘the_content’, $meal_chef[‘bio’]) ?>
<?php if ($meal_chef[‘social_profiles’][‘facebook’]) : ?>
” class=”p-2″><span
class=”fa fa-facebook”></span>
<?php endif; ?>
<?php if ($meal_chef[‘social_profiles’][‘twitter’]) : ?>
” class=”p-2″><span
class=”fa fa-twitter”></span>
<?php endif; ?>
<?php if ($meal_chef[‘social_profiles’][‘instagram’]) : ?>
”
class=”p-2″><span class=”fa fa-instagram”></span>
<?php endif; ?>
</p>
</div>
</div>
</div>
</div>
<?php endforeach; ?><!– <div class=”col-md-4″></div> –>
</div><?php endif; ?>
</div>
</div> <!– .section –>But image get broken.
Attachments:
You must be logged in to view attached files. -
July 6, 2020 at 12:25 pm #10717
SteveKeymaster@rashedul007– Welcome to the Piklist Community!
If you just output
$meal_chef[‘chef_image’], what so do you get? -
July 6, 2020 at 11:29 pm #10718
rashedul007ParticipantThanks, Steve for your response. It gives below output:
array (size=1) 0 => string '44' (length=2)and
array (size=1) 0 => string '43' (length=2) -
July 6, 2020 at 11:33 pm #10719
rashedul007Participant@sbruner,eagerly waiting for your reply.
-
July 7, 2020 at 5:17 am #10720
SteveKeymasterThe
0key is where the ID is stored.
Update this:
$meal_chef_image = wp_get_attachment_image_src($meal_chef[‘chef_image’], ‘medium’);To this (add [0]):
$meal_chef_image = wp_get_attachment_image_src($meal_chef[‘chef_image’][0], ‘medium’);it’s always a good idea to output your data arrays so you can verify.
-
July 7, 2020 at 7:01 am #10721
rashedul007ParticipantThanks a lot @sbruner for your quick response.
-
July 7, 2020 at 9:54 am #10722
SteveKeymasterYou’re very welcome! Happy to help.
If you have a few minutes we’d appreciate if you could leave a quick review on Piklist. It really motivates us and helps the project: https://wordpress.org/support/plugin/piklist/reviews/
-
-
AuthorPosts
- The topic ‘Image retrieving problem from group meta field’ is closed to new replies.