Support » Plugin: Pods - Custom Content Types and Fields » Displaying a page's custom fields

  • Resolved Josh

    (@joshdev)


    I have used pods as an extension of the wordpress pages in order to display three ‘featured item’ boxes on the home page, the first of these boxes will also be used on the rest of the site’s pages. I can successfully call a certain pages entries into the custom fields using

    <?php
    $where 	= array('limit'=>-1);
    $page	= new Pod('page', $where);
    $page_array   = array(); 
    
    	while ( $page->fetchRecord() ) :
    
    	$featuredImg1	= $page->get_field('featured_1_image.guid');
    	$featuredText1	= $page->get_field('featured_1_label');
    	$featuredLink1	= $page->get_field('featured_1_link');
    
    	$page_array[]	= array ('src' => $featuredImg1,
    'featured_1_label' => $featuredText1,
    'featured_1_link' => $featuredLink1);
    
    	endwhile;
    ?>

    and

    <?php $page = $page_array[21]; ?>

    in my page.php file but I don’t want to have to specify a specific page, I would like to call the current page’s entries dynamically but can’t seem to figure out how to make it work properly.

    http://wordpress.org/plugins/pods/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Josh Pollock

    (@shelob9)

    Josh-

    You are using Pods 1.X syntax. In 2.X syntax it would look like:

    <?php
    $params 	= array('limit'=>-1);
    $page	= pods('page', $params);
    $page_array   = array(); 
    
    	while ( $page->fetch() ) :
    
    	$featuredImg1	= $page->field('featured_1_image.guid');
    	$featuredText1	= $page->field('featured_1_label');
    	$featuredLink1	= $page->field('featured_1_link');
    
    	$page_array[]	= array ('src' => $featuredImg1,
    'featured_1_label' => $featuredText1,
    'featured_1_link' => $featuredLink1);
    
    	endwhile;
    ?>

    Please see the docs for the pods class and its methods for more information.

    Take care,
    Josh

    BTW Awesome screen name. How early did you have to sign up to get that?

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    For the current page, you could try:

    $page = pods( 'page', get_the_ID() );

    After reading through the docs a bit more I still haven’t been able to figure this problem out since the only experience I have with pods is for looping through items and not trying to display the particular page’s item.

    Scott, for some reason my page ids aren’t lining up correcting with the pod extensions. when I call the page id and just echo it out it displays a different number than the one I have to use in the array. for example the page id of the page I’m testing with is 7 but 21 is the number I have to put in to display that particular page’s items (as seen below).

    <?php $page = $page_array[21]; ?>

    P.S. Josh I actually only signed up for the forums about 5 minutes prior to this post so I guess I just lucked out on the screen name (assuming you’re referring to the JoshDev name)

    update, using Scott’s method of declaring my $page value instead of the $params causes my page id to echo out at 1 on all pages.

    Plugin Contributor Josh Pollock

    (@shelob9)

    Josh-

    The problem with using get_the_id() in your situation is it will return the ID of the front page, not the posts you need. You could specify the IDs when you call the pods class, like this:

    $ids = array(
    //comma separated list of ids here
    );
    $page = pods('page', $ids );

    BTW-
    JoshDev is pretty cool, wish I had thought of that, had a lot of time on you to do it too.

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Comma-separated list of IDs won’t work, but that’s a pretty good idea for a feature.

    I have this feature on hold for the moment, I’ll update when I get back around to trying to figure it out.

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Try this:

    // List of Page IDs
    $ids = array(
        1,
        34,
        45
    );
    
    $page = pods( 'page', array( 'where' => 't.ID IN ( ' . implode( ', ', $ids ) . ' )', 'limit' => -1 ) );

    Then you can use the $page->fetch() loop to loop through the pages and output content as needed.

    I found an alternative solution to this.

    I created a relationship pod that will allow my customer to toggle a feature on for any pages of their choosing, this allows them to manage which pages are receiving a specific feature much easier than my original attempted method.

    Example Code:

    <ul class="featuredWrapper">
    
    <?php
    	$pageID = get_the_id();
    	$params = array(
    		'where'=>"display.ID = $pageID",
    		'limit'=>1);
    	$features = pods( 'feature', $params );
    ?>
    
    	<li class="featuredBox featured1">
    		<?php while ( $features->fetch() ) : ?>
    			<div class="text"><?php echo $features->display( 'post_title' ); ?></div>
    				<?php echo $features->display( 'post_content' ); ?>
    		<?php endwhile ?>
    	</li>
    </ul>

    Thanks for the help.

    I hate to do this Scott, but your not answering my post as you said you would, could you please take a minute ?

    http://wordpress.org/support/topic/pods-use-existing-database?replies=1

    Plugin Contributor Josh Pollock

    (@shelob9)

    Carsten-

    I just replied to that post. Sorry for missing it.

    -Josh

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Displaying a page's custom fields’ is closed to new replies.