WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] php echo not referencing met content (8 posts)

  1. mypcsolutions
    Member
    Posted 1 year ago #

    Hello everyone,
    my site is here:

    http://www.joyousvacations.com

    I am new to PHP, been trying to figure this out for a while now.

    I have a metaboxes.php file that has some arrays in it and here is the code i am trying to reference:

    ?php
    // Include & setup custom metabox and fields
    $prefix = '_ct_'; // start with an underscore to hide fields from custom fields list
    add_filter( 'cmb_meta_boxes', 'ct_metaboxes' );
    function ct_metaboxes( $meta_boxes ) {
    	global $prefix;
            $meta_boxes[] = array(
    		'id' => 'rentalname',
    		'title' => 'Rental Name',
    		'pages' => array('listings'), // post type
    		'context' => 'normal',
    		'priority' => 'high',
    		'show_names' => false, // Show field names on the left
    		'fields' => array(
    			array(
    				'name' => 'Rental Name',
    				'desc' => 'Type the name of your rental here.',
    				'id' => $prefix . 'rentalname',
    				'type' => 'text'
    			),
    		)
    	);

    I also have a single-listings.php file that I am trying to pull the Rental Name and display on the site:

    <?php echo get_post_meta($post->ID, "_ct_rentalname", true); ?>

    All I get is empty space, can someone let me know what I am doing wrong? Any help would be appreciated.

    http://codex.wordpress.org/Installing_WordPress

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    I wonder if you just need to call for rentalname? The ID of the overall array, not the specific ID within the fields?

    I'm not familiar with the meta framework you are using... so not 100%

  3. mypcsolutions
    Member
    Posted 1 year ago #

    There are other arrays in the metaboxes.php files, maybe I could add the array as a section in one of those. I will try it and see hat changes.

    I haven't coded anything with php before, but have looked at a few online tutorials.

  4. mypcsolutions
    Member
    Posted 1 year ago #

    you mean '<?php echo $post->ID, "_ct_rentalname", true; ?>'

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    <?php echo get_post_meta($post->ID, 'rentalname', true); ?>

    Was my guess ... but I think I might be off base here (I don't know the whole cmb_meta_boxes function to fully understand the implementation of your code)

    Also, I believe you should be using single, and not double quotes in there - I'm not sure if that would cause an issue

  6. mypcsolutions
    Member
    Posted 1 year ago #

    I tried the single quotes and it didn't produce any change.

    Here is the beginning of the single-listings page...basically, I am trying to display the name of a home and display it above the title. That is why I created the array. The array creates a field on each listings page that I fill out with the name of the rental, and then of course call that and display it on the appropriate page.

    <?php
    /**
     * Listing Single Template
     *
     * @package WP Pro Real Estate 3
     * @subpackage Template
     */
    
    global $ct_options;
    
    get_header(); ?>
    
    		<section class="sixteen columns marT20">
    
    			<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                    <div class="eleven columns left">
    
                        <div id="first-image-for-print-only">
    						<?php ct_first_image_print(); ?>
                        </div>
    
    <?php echo get_post_meta($post->ID, 'rentalname', true); ?>
    <h3 class="address marB0"><?php the_title(); ?></h3>
                        <p class="location"><?php city(); ?>, <?php state(); ?> <?php zipcode(); ?></p>
  7. mypcsolutions
    Member
    Posted 1 year ago #

    Figured it out, I just deleted and added the echo line and it worked.

  8. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    I'm glad you got it figured out!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags