WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
[resolved] Retrieve Custom Fields by Name With Content Type ID? (3 posts)

  1. thecraigmcrae
    Member
    Posted 5 months ago #

    I'm building a single scrolling page with each section represented as a custom content type, and each using a similarly structured custom fields.
    The issue I'm having is pulling in the image field within each section using the :to_image_src method.

    Here's an example

    Define sections:
    $hero = get_post_complete(5);
    $compay = get_post_complete(10);
    $services = get_post_complete(15);

    Pull in content in a section via array:
    <h1><?php print $hero['mainheading']; ?></h1>
    <h5><?php print $hero['subheading']; ?></h5>

    Now I get stuck trying to pull in the image..
    wp_get_attachment_image($image_id); works, but I don't want to have to get the ID every time, I need it to be dynamic.
    <img src="<?php print_custom_field('flyout_image:to_image_src'); ?>" /> does not work in this context.
    <img src="<?php print_custom_field('flyout_image:to_image_src'); ?>" />

    <?php print $hero['flyout_image']; ?> returns the number as you know.
    <?php print $hero['flyout_image:to_image_src']; ?> does not work.

    As you can see, I'm lost and have tried many other combinations in addition to the ones illustrated above. Any help would be fantastic.

    http://wordpress.org/plugins/custom-content-type-manager/

  2. thecraigmcrae
    Member
    Posted 5 months ago #

    I think I may have found a workaround.

    <?php print wp_get_attachment_image($hero['flyout_image'], array(579,462)); ?>

  3. fireproofsocks
    Member
    Plugin Author

    Posted 5 months ago #

    Glad you found a solution, I would have suggested a variable for the image id too.

    Yeah, you can't use $hero['flyout_image:to_image_src'] -- you are referencing an array key that does not exist. If you turn on PHP notices (or set WP_DEBUG to true), you will see PHP notices when you try to do that. You can *only* tag on those types of modifiers as arguments to the get_custom_field arguments -- that function processes the arguments and uses them to modify the values. And you can't use get_custom_field to operate on values on another post, only on the current one. You're going down 2 levels here, and it can get confusing. Your solution is the correct way to operate on a raw id from a related post.

Reply

You must log in to post.

About this Plugin

About this Topic