- This topic has 28 replies, 3 voices, and was last updated 5 years, 10 months ago by
Steve.
-
AuthorPosts
-
-
March 16, 2016 at 5:41 pm #6100
4michaelcolemanMemberI just started working with Piklist and love creating the CPT. I am building a summit event page for our company that has general venue information, speakers and sponsors. That was the fun easy part.
At this point I’m unable to get anything to display on the front end. Tried everything I know and all I get is a 404 page not found.
Here is what I have put in the my function.php
add_filter('piklist_post_types', 'piklist_event_post_type'); function piklist_event_post_type($post_types) { $post_types['piklist_event'] = array( 'labels' => piklist('post_type_labels', 'Company Summit'), 'title' => __('Enter Event Title'), 'public' => true, 'rewrite' => array( 'slug' => '/event/' ), 'supports' => array( 'title', 'editor', 'thumbnail', ), ); return $post_types; }Here is are examples of the field groups I’m creating.
<?php /* Title: Event Speakers Post Type: piklist_event Order: 80 */ piklist('field', array( 'type' => 'group', 'field' => 'speaker_group_add_more', 'add_more' => true, 'description' => 'Add speakers as needed', 'fields' => array( array( 'type' => 'text', 'field' => 'name', 'label' => 'Full Name', 'required' => true, 'columns' => 6 ), array( 'type' => 'text', 'field' => 'title', 'label' => 'Title', 'required' => true, 'columns' => 6 ), array( 'type' => 'textarea', 'field' => 'bio', 'label' => 'BIO', 'required' => true, 'attributes' => array( 'rows' => 8, 'class' => 'large-text', ), 'columns' => 12 ), array( 'type' => 'text', 'field' => 'topic', 'label' => 'Event Topic', 'columns' => 6 ), array( 'type' => 'datepicker', 'field' => 'date', 'label' => 'Date', 'attributes' => array( 'class' => 'text' ), 'options' => array( 'dateFormat' => 'M d, yy', 'firstDay' => '0' ), 'columns' => 3 ), array( 'type' => 'text', 'field' => 'time', 'label' => 'Time', 'columns' => 3 ), array( 'type' => 'file', 'field' => 'upload_media', 'label' => __('Speaker Photo', 'piklist'), 'description' => __('Image Size: 00px X 00px','piklist'), 'required' => true, 'options' => array( 'modal_title' => __('Add Photo', 'piklist'), 'button' => __('Add Image', 'piklist'), ), 'columns' => 4 ), ), 'on_post_status' => array( 'value' => 'lock' ) )); ?><?php /* Title: Event Sponsors Post Type: piklist_event Order: 100 */ piklist('field', array( 'type' => 'group', 'field' => 'sponsor_group_add_more', 'add_more' => true, 'description' => 'Add sponsors as needed', 'fields' => array( array( 'type' => 'text', 'field' => 'company', 'label' => 'Company Name', 'required' => true, 'columns' => 12 ), array( 'type' => 'textarea', 'field' => 'desc', 'label' => 'Description', 'required' => true, 'attributes' => array( 'rows' => 8, 'class' => 'large-text', ), 'columns' => 12 ), array( 'type' => 'select', 'field' => 'level', 'label' => 'Sponsor Level', 'required' => true, 'attributes' => array( 'class' => 'text' ), 'choices' => array( '' => '-- Select --', 'platinum' => 'Platinum', 'gold' => 'Gold', 'silver' => 'Silver', ), 'columns' => 4 ), array( 'type' => 'file', 'field' => 'upload_media', 'label' => __('Company Logo', 'piklist'), 'description' => __('Image Size: 00px X 00px','piklist'), 'required' => true, 'options' => array( 'modal_title' => __('Add Logo', 'piklist'), 'button' => __('Add Logo', 'piklist'), ), 'columns' => 4 ), ), 'on_post_status' => array( 'value' => 'lock' ) )); ?> -
March 16, 2016 at 6:38 pm #6101
jrcreativeMemberYour slug should be simply ‘events’ and not ‘/events/’. Other then that, it looks like you’re on the right track.
You’ll likely want to have a custom page template for displaying all of your custom post meta. I generally start with duplicating my theme’s
single.phpand renaming it with the post type appended to the end (per WordPress template hierarchy).single-piklist_event.phpwould be yours based on the code above.Once you create your first event, you can
print_r(get_post_meta(get_the_ID())in your new page template and start echoing out your fields as needed. -
March 16, 2016 at 7:00 pm #6102
4michaelcolemanMemberModified the slug. And renamed my single.php page to single-piklist_event.php and added the print_r to it.
<?php get_header(); print_r(get_post_meta(get_the_ID()) get_footer(); ?>And still getting the same results. Simple 404: page not found.
-
March 16, 2016 at 7:54 pm #6103
jrcreativeMemberTry resaving permalinks settings. Sometimes just clicking save will do it, or sometimes you have to choose another option and save, and then go back to the one you want.
-
March 16, 2016 at 11:17 pm #6104
4michaelcolemanMemberWell, it doesn’t 404 anymore. But not seeing anything other then the header and footer.
-
March 17, 2016 at 10:13 am #6106
SteveKeymasterSet wp_debug to true. Will show you any errors.
-
March 17, 2016 at 4:46 pm #6109
4michaelcolemanMemberThank you, this helps. Can you also point me to where I can get more information on images. I am using the following code and it provides the ability to load several images, I just want one.
array( 'type' => 'file', 'field' => 'upload_media', 'label' => __('Speaker Photo', 'piklist'), 'description' => __('Image Size: 00px X 00px','piklist'), 'required' => true, 'options' => array( 'modal_title' => __('Add Photo', 'piklist'), 'button' => __('Add Image', 'piklist'), ),The thought would be to have a button to load a photo. Once the photo is loaded I no longer need the button. If you delete the photo then the button comes back.
-
March 17, 2016 at 6:16 pm #6111
4michaelcolemanMemberAlso still struggling with looping through my speaker custom data and displaying the information on my page. Which would be the best way to go about displaying the Speaker Name, Title, Company, BIO, Topic, Date and Time. And how do I pull in the speaker photo?
Here is the code set that I am using for the post:
<?php /* Title: Event Speakers Post Type: piklist_event Order: 80 */ piklist('field', array( 'type' => 'group', //'field' => 'speaker_group_add_more', 'add_more' => true, //'description' => 'Add speakers as needed', 'fields' => array( array( 'type' => 'text', 'field' => 'speaker_name', 'label' => 'Full Name', 'required' => true, 'columns' => 6 ), array( 'type' => 'text', 'field' => 'speaker_title', 'label' => 'Title', 'required' => true, 'columns' => 6 ), array( 'type' => 'text', 'field' => 'speaker_company', 'label' => 'Company', 'required' => true, 'columns' => 12 ), array( 'type' => 'textarea', 'field' => 'speaker_bio', 'label' => 'BIO', 'required' => true, 'attributes' => array( 'rows' => 8, 'class' => 'large-text', ), 'columns' => 12 ), array( 'type' => 'text', 'field' => 'speaker_event_topic', 'label' => 'Event Topic', 'columns' => 6 ), array( 'type' => 'datepicker', 'field' => 'speaker_event_date', 'label' => 'Date', 'attributes' => array( 'class' => 'text' ), 'options' => array( 'dateFormat' => 'M d, yy', 'firstDay' => '0' ), 'columns' => 3 ), array( 'type' => 'text', 'field' => 'speaker_event_time', 'label' => 'Time', 'columns' => 3 ), array( 'type' => 'file', 'field' => 'upload_media', 'label' => __('Speaker Photo', 'piklist'), 'description' => __('Image Size: 00px X 00px','piklist'), 'required' => true, 'options' => array( 'modal_title' => __('Add Photo', 'piklist'), 'button' => __('Add Image', 'piklist'), ), 'columns' => 4 ), ), 'on_post_status' => array( 'value' => 'lock' ) )); ?> -
March 18, 2016 at 2:06 pm #6118
SteveKeymaster@4michaelcoleman– Are you using out latest beta? If so, you should see an very simple array to loop through.
-
March 18, 2016 at 2:51 pm #6121
4michaelcolemanMemberUsing 0.9.4.29, were would I go to see this?
-
March 18, 2016 at 2:54 pm #6122
SteveKeymaster1) upgrade to the latest beta.
2) uncomment this://'field' => 'speaker_group_add_more',
3) Save your data
4) Pull your data with get_post_meta()Then use a foreach loop to go through your data.
-
March 18, 2016 at 3:08 pm #6123
4michaelcolemanMemberFrom what I see I am on the latest. Am I missing something here?
-
March 18, 2016 at 3:10 pm #6124
SteveKeymaster0.9.4.29 is the latest on WordPress.org. We have a beta version that makes the add more array easier to use.
-
March 18, 2016 at 3:14 pm #6125
4michaelcolemanMemberThanks Steve will check it out.
-
March 18, 2016 at 7:23 pm #6127
4michaelcolemanMemberHey Steve, did the upgrade but was not able to find information on add more array.
-
March 21, 2016 at 3:48 pm #6134
4michaelcolemanMemberSteve –
Still have not been successful in outputting the data of my Speaker Group (code below) in a loop. I must have spent several days trying to piece together code from several searches on the subject. The only thing I have been able to do is get just get the first values on my Add More group.
Here is my current code:
piklist('field', array( 'type' => 'group', 'field' => 'speaker_group', 'add_more' => true, //'description' => 'Add speakers as needed', 'fields' => array( array( 'type' => 'text', 'field' => 'speaker_name', 'label' => 'Full Name', 'required' => true, 'columns' => 6 ), array( 'type' => 'text', 'field' => 'speaker_title', 'label' => 'Title', 'required' => true, 'columns' => 6 ), array( 'type' => 'text', 'field' => 'speaker_company', 'label' => 'Company', 'required' => true, 'columns' => 12 ), array( 'type' => 'textarea', 'field' => 'speaker_bio', 'label' => 'BIO', 'required' => true, 'attributes' => array( 'rows' => 8, 'class' => 'large-text', ), 'columns' => 12 ), array( 'type' => 'text', 'field' => 'speaker_event_topic', 'label' => 'Event Topic', 'columns' => 6 ), array( 'type' => 'datepicker', 'field' => 'speaker_event_date', 'label' => 'Date', 'attributes' => array( 'class' => 'text' ), 'options' => array( 'dateFormat' => 'M d, yy', 'firstDay' => '0' ), 'columns' => 3 ), array( 'type' => 'text', 'field' => 'speaker_event_time', 'label' => 'Time', 'columns' => 3 ), array( 'type' => 'file', 'field' => 'upload_basic', 'scope' => 'post_meta', 'label' => __('Speaker Photo','piklist'), //'description' => __('Description text','piklist'), 'required' => false, 'options' => array( 'basic' => false ), 'columns' => 4 ), /* array( 'type' => 'file', 'field' => 'upload_media', 'label' => __('Speaker Photo', 'piklist'), 'description' => __('Image Size 00px X 00px','piklist'), 'required' => true, 'options' => array( 'modal_title' => __('Add Photo', 'piklist'), 'button' => __('Add Image', 'piklist'), ), 'columns' => 4 ), */ ), 'on_post_status' => array( 'value' => 'lock' ) )); ?>Can you help with a simple loop that will output these values on my post?
-
March 22, 2016 at 11:32 am #6138
SteveKeymaster@4michaelcoleman– You choose one of the harder configurations to display 😉 A Group, Add More, with a Media Uploader is a bunch of arrays you need to loop through.
Here’s the code you need. Let me know if the comments make sense:
/ Get the field value. $sponsor_groups = get_post_meta($post->ID, 'sponsor_group', false ); // Since the field value is an add more field, it's array, so we need to loop through it foreach ($sponsor_groups as $sponsor_group => $group) { // loop through each group foreach ($group as $group_info) { echo $group_info['company']; echo $group_info['desc']; echo $group_info['level']; // upload field is also an array that stores the image ID $image_ids = $group_info['upload_media']; // loop through each image ID to get the image info from WordPress foreach ($image_ids as $image) { $image_info = get_post($image); $title = $image_info->post_title; $description = $image_info->post_content; $caption = $image_info->post_excerpt; echo 'title:' . $title; echo 'description:' . $description; echo 'caption:' . $caption; echo 'img src="' . wp_get_attachment_url($image) . '" alt="" />'; } } } -
March 22, 2016 at 1:30 pm #6139
4michaelcolemanMemberThanks Steve –
In short this is what I am trying to fit the media into along with a popup box for the bio. There will be one image and general content for each speaker. I assume that I only need to echo the image url and speaker name for the alt. Do I need to use both the loops to pull in the image and make this happen?
My code:
<div class="col-lg-6 col-xs-12"> <div data-toggle="modal" data-target=“speaker-name”> <div class="speaker-img img-responsive"> <img class="pull-left" src=“image-path” alt=“speaker-name” width="190"> </div> <div class="speaker-name">speaker-name</div> <div class="speaker-title">speaker-title</div> <div class="speaker-company">speaker-company</div> <div class="topic">speaker-topic</div> <div class="overview"> overview <i class="fa fa-angle-right"></i> </div> </div> </div> -
March 22, 2016 at 1:37 pm #6140
4michaelcolemanMemberThis actually is what I’ve done for pulling in each speaker. Trying to determine how to add your loop for the image.
<section class="speaker-table speaker-overlay"> <div class="container clearfix"> <div class="row"> <div class="col-xs-12"> <h3><span>Featured</span> Speakers</h3> </div> </div> <?php $speakers = get_post_meta($post->ID, 'speaker_group', true); if ($speakers): ?> <?php foreach($speakers as $post): ?> <div class="col-lg-6 col-xs-12"> <div class="speaker-name"><?php echo $post['speaker_name']; ?></div> <div class="speaker-img img-responsive"> <img class="pull-left" src="<?php echo $post['wp_get_attachment_url($image)']; ?>" alt="<?php echo $post['speaker_name']; ?>" width="190"> </div> <div class="speaker-title"><?php echo $post['speaker_title']; ?></div> <div class="speaker-company"><?php echo $post['speaker_company']; ?></div> <div class="topic"><?php echo $post['speaker_event_topic']; ?></div> <div class="topic"><?php echo $post['speaker_event_date']; ?></div> <div class="topic"><?php echo $post['speaker_event_time']; ?></div> <div class="overview">overview <i class="fa fa-angle-right"></i></div> </div> <?php endforeach; ?> <?php wp_reset_query(); ?> <?php endif; ?> </div> </section> -
March 22, 2016 at 4:10 pm #6141
4michaelcolemanMemberAlso, if I wanted to filter out a name of a speaker, how would I go about doing that without having to delete all the records?
So say I only want speakers with the name “sam”, or don’t want speakers with the name “steve”?
-
March 22, 2016 at 4:41 pm #6142
SteveKeymasterThis is untested, but should work. Replace your image div with this:
<img class="pull-left" src="" alt="" width="190"> -
March 22, 2016 at 8:10 pm #6143
4michaelcolemanMemberThis is what I am getting…
Notice: Undefined index: upload_media in –file path– on line 70
Warning: Invalid argument supplied for foreach() in –file path– on line 71
-
March 22, 2016 at 8:25 pm #6144
4michaelcolemanMemberHere is what I changed it to, don’t get the errors, but not getting the images. Just broken graphics.
<?php $image_ids = $post['upload_basic']; ?> <?php foreach ($image_ids as $image): ?> <img class="pull-left" src="<?php echo $post['wp_get_attachment_url($image)']; ?>" alt="<?php echo $post['speaker_name']; ?>" width="190"> <?php endforeach; ?> -
March 22, 2016 at 11:06 pm #6145
SteveKeymasterI need to see the full code. Please post
-
March 23, 2016 at 1:06 am #6149
4michaelcolemanMemberHere it is…
<section class="speaker-table speaker-overlay"> <div class="container clearfix"> <div class="row"> <div class="col-xs-12"> <h3><span>Featured</span> Speakers</h3> </div> </div> <?php $speakers = get_post_meta($post->ID, 'speaker_group', true); if ($speakers): ?> <?php foreach($speakers as $post): ?> <div class="col-lg-6 col-xs-12"> <div class="speaker-name"><?php echo $post['speaker_name']; ?></div> <div class="speaker-img img-responsive"> <?php $image_ids = $post['upload_basic']; ?> <?php foreach ($image_ids as $image): ?> <img class="pull-left" src="<?php echo $post['wp_get_attachment_url($image)']; ?>" alt="<?php echo $post['speaker_name']; ?>" width="190"> <?php endforeach; ?> </div> <div class="speaker-title"><?php echo $post['speaker_title']; ?></div> <div class="speaker-company"><?php echo $post['speaker_company']; ?></div> <div class="topic"><?php echo $post['speaker_event_topic']; ?></div> <div class="topic"><?php echo $post['speaker_event_date']; ?></div> <div class="topic"><?php echo $post['speaker_event_time']; ?></div> <div class="overview">overview <i class="fa fa-angle-right"></i></div> </div> <?php endforeach; ?> <?php wp_reset_query(); ?> <?php endif; ?> </div> </section> -
March 23, 2016 at 10:03 am #6151
SteveKeymasterI’m not getting any errors. Your img tag is incorrect. Should be:
-
March 23, 2016 at 11:32 am #6160
4michaelcolemanMemberOK, that did it. Thanks!
-
March 23, 2016 at 2:33 pm #6163
SteveKeymasterNice!
-
-
AuthorPosts
- The topic ‘No Preview or Post’ is closed to new replies.