Viewing 27 reply threads
  • Author
    Posts
    • #6100

      I 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'
          )
        ));
        
      ?>
    • #6101
      jrcreative
      Member

      @4michaelcoleman

      Your 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.php and renaming it with the post type appended to the end (per WordPress template hierarchy). single-piklist_event.php would 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.

    • #6102

      Modified 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.

    • #6103
      jrcreative
      Member

      @4michaelcoleman

      Try 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.

    • #6104

      Well, it doesn’t 404 anymore. But not seeing anything other then the header and footer.

    • #6106
      Steve
      Keymaster

      Set wp_debug to true. Will show you any errors.

    • #6109

      Thank 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.

      • #6117
        Steve
        Keymaster

        You may want to use the upload_basic field instead of upload_media. It’s simpler.

    • #6111

      Also 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'
            )
        ));
      ?>
    • #6118
      Steve
      Keymaster

      @4michaelcoleman– Are you using out latest beta? If so, you should see an very simple array to loop through.

    • #6121

      Using 0.9.4.29, were would I go to see this?

    • #6122
      Steve
      Keymaster

      1) 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.

    • #6123

      From what I see I am on the latest. Am I missing something here?

    • #6124
      Steve
      Keymaster

      0.9.4.29 is the latest on WordPress.org. We have a beta version that makes the add more array easier to use.

      You can learn more here >

    • #6125

      Thanks Steve will check it out.

    • #6127

      Hey Steve, did the upgrade but was not able to find information on add more array.

    • #6134

      Steve –

      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?

    • #6138
      Steve
      Keymaster

      @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="" />';
      		}
      	}
      }
      
    • #6139

      Thanks 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>
    • #6140

      This 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>
    • #6141

      Also, 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”?

    • #6142
      Steve
      Keymaster

      This is untested, but should work. Replace your image div with this:

      <img class="pull-left" src="" alt="" width="190">
    • #6143

      This 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

    • #6144

      Here 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; ?>
    • #6145
      Steve
      Keymaster

      I need to see the full code. Please post

    • #6149

      Here 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>
    • #6151
      Steve
      Keymaster

      I’m not getting any errors. Your img tag is incorrect. Should be:

      
      
    • #6160

      OK, that did it. Thanks!

    • #6163
      Steve
      Keymaster

      Nice!

Viewing 27 reply threads
  • The topic ‘No Preview or Post’ is closed to new replies.