Getting the cost custom field only, not both cost and expires...

Hi,
I want to pull the cost custom field only and not both cost and expires which is the default...

Could you please pass along the code to get it :slight_smile:

Thanks,

Danny.

  • DavidM
    • DEV MAN’s Mascot

    Hi Danny,

    I'm not sure I understand you, could you clarify?

    The embed code provides the information you need and you can technically use that anywhere in your theme to pull the cost. It's at Classifieds > Content Types > Custom Fields.

    Does that embed code provide what you're looking for?

    Cheers,
    David

  • Danny
    • Design Lord, Child of Thor

    I am not a wordpress master so need help with editing this code to provide me with only the cost custom field value.. I do not want to pull out the expired custom field value as well...

    <table class="cf-custom-fields" >
                                <?php $prefix = '_ct_'; $i = 1; ?>
                                <?php $custom_fields = get_site_option('ct_custom_fields'); ?>
                                <?php foreach ( $custom_fields as $custom_field ): ?>
                                    <?php $field_value = get_post_meta( get_the_ID(), $prefix . $custom_field['field_id'], true ); ?>
                                    <tr class="<?php if ( $i % 2 == 0 ) echo 'alt' ?>">
                                        <th><?php echo $custom_field['field_title']; ?></th>
                                        <td>
                                            <?php
                                            if ( is_array( $field_value ) ) {
                                                foreach ( $field_value as $value )
                                                    echo $value  . ' ';
                                            } else {
                                                echo $field_value;
                                            } ?>
                                        </td>
                                    </tr>
                                    <?php $i++; ?>
                                <?php endforeach; ?>
                            </table>
  • Danny
    • Design Lord, Child of Thor

    Something here<?php $field_value = get_post_meta( get_the_ID(), $prefix . $custom_field['field_id'], true ); ?> but after searching and fruitless testing, I just can't seem to get it to work :slight_frown:

  • Philip John
    • DEV MAN’s Apprentice

    Hiya,

    If you want to only show the expired field you should replace all of this:

    <?php foreach ( $custom_fields as $custom_field ): ?>
                                    <?php $field_value = get_post_meta( get_the_ID(), $prefix . $custom_field['field_id'], true ); ?>
                                    <tr class="<?php if ( $i % 2 == 0 ) echo 'alt' ?>">
                                        <th><?php echo $custom_field['field_title']; ?></th>
                                        <td>
                                            <?php
                                            if ( is_array( $field_value ) ) {
                                                foreach ( $field_value as $value )
                                                    echo $value  . ' ';
                                            } else {
                                                echo $field_value;
                                            } ?>
                                        </td>
                                    </tr>
                                    <?php $i++; ?>
                                <?php endforeach; ?>

    with the embed code located in the page suggested by David previously.

    If you're not comfortable with coding then it's highly advisable to hire a developer to do modifications like this for you.

    Phil

  • Danny
    • Design Lord, Child of Thor

    AHHHHH!!!! My Bad.. Sorry, I missed the part about going to custom fields -> embed.. Did not know it was there..

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

    PERFECT!!!

    :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.