Support » Fixing WordPress » php echo not referencing met content

  • Resolved mypcsolutions


    Hello everyone,
    my site is here:

    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:

    // 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(
    				'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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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%

    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.

    you mean ‘<?php echo $post->ID, “_ct_rentalname”, true; ?>’

    <?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

    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.

     * 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(); ?>
    <?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>

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

    I’m glad you got it figured out!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘php echo not referencing met content’ is closed to new replies.