?
Solved

Custom fields and excerpts

Posted on 2014-01-10
5
Medium Priority
?
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 1500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
In this blog, I will share you some basic tips for content marketing and to rank your website on Google.
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 purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

762 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