Solved

Custom fields and excerpts

Posted on 2014-01-10
5
390 Views
Last Modified: 2014-01-18
Dear experts,

Do you know how can I add custom fields to the post excerpts? I created a custom post type named places and wanted to add two custom fields named first_name and address. I would like to add to the excerpt those two custom fields instead of the usual short paragraph.
The way I am pulling my custom post type is as follows:

<?php
/*
 * Template Name: Places to go
 */



// Replace the loop.
remove_action(  'genesis_loop',   'genesis_do_loop' );
add_action( 'genesis_loop',   'places_custom_loop' );

genesis();

function places_custom_loop() {
 
            echo '<h1 class="entry-title">' . get_the_title() . '</h1>';
            the_content();
            //WP Query Start
            $per_page = 3;
            $places_args = array(
                'post_type' => 'places',
                'posts_per_page' => $per_page,
                                'paged' => get_query_var( 'paged' )
            );
            $places = genesis_custom_loop( $places_args );
}
 ?>

In the Advance Custom Fields plugin docs says that I have to echo out the custom fields like this : <?php the_field('first_name') ?>; But honestly I have no idea how to use it in the code above.

Could someone please help me?

Thanks,

Janeth
0
Comment
Question by:glepiza
  • 3
  • 2
5 Comments
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
ID: 39772922
You don't need the opening and closing <?php ?> stuff since the code above is already PHP.

            echo '<h1 class="entry-title">' . get_the_title() . the_field('first_name') .  '</h1>';
0
 

Accepted Solution

by:
glepiza earned 0 total points
ID: 39774012
Hello Jason, thank you for your answer,

I did some reading and I ended up doing this:

function places_loop() {
    $loop = new WP_Query( array( 'post_type' => 'places', 'posts_per_page' => 4, 'paged' => get_query_var( 'paged' ) ) ); ?>
                <h1><?php the_title(); ?></h1>
            <div id="specials">
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
            
            <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
            <div id="post-<?php the_ID(); ?>" class="places-list">
            <?php//use the genesis_get_custom_field template tag to display each custom field value ?>
            <h3><?php echo the_field('phone_number'); ?></h3>

            </div><!--end #specials -->
    <?php endwhile;?>
    <?php
    }
 
    genesis();

The only thing that I see is not working is the pagination, I am not getting the pagination.. Could you please help me on this?

Thanks,

Winter
0
 

Author Comment

by:glepiza
ID: 39774824
Anyone?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 39774989
Pagination is a different question. You should close this down and open a new question dealing with that.
0
 

Author Closing Comment

by:glepiza
ID: 39790463
The answer provided by the experts did not work but it gave me an idea how to place the code on my excerpt. So after a long reading I ended up adding the code to the excerpt as I posted on the answers and it did work. Thanks!!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we will look at our content management system as a whole, to get an idea of how we will start to manage these content items.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question