Solved

Custom fields and excerpts

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress syntax error 1 40
Wordpress theme to easily (hopefully!) make this type of site 1 36
WordPress Themes 10 34
Magento slider issue 1 6
WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now