Solved

Custom fields and excerpts

Posted on 2014-01-10
5
387 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

What's this? As a volunteer Page Editor for Experts-Exchange.com, I have noticed that many authors also have blogs, and pull articles from their blogs to post at Experts-Exchange. I appreciate each author sharing their blog content with our site …
This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now