Support » Plugin: Toolset Types - Custom Post Types, Custom Fields and Taxonomies » [Plugin: Types – Custom Fields and Custom Post Types Management] Adding Alt and Title Text to Custom

  • Resolved klongdesigns

    (@klongdesigns)


    I’ve got the custom meta setup for an image upload. This image has a title and alt text assigned to it. I’m trying to find out how to display that text when I display the image. In the documentation for the Types API, it says that i can set the alt and title parameters:

    ‘alt’ => alternative text e.g. ‘My image’
    ‘title’ => hover text e.g. ‘My image’

    But how do I pull the alt and title text that was from the image when I uploaded it?

    I’m pulling a random post that has an image attached to it, so the alt and title text needs to be the same as that random post’s image, or else I could statically assign it an alt and title (per the api), but I don’t know how to pull the information that is already in the database and assign it to the alt and title parameters of the API.

    http://wordpress.org/extend/plugins/types/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter klongdesigns

    (@klongdesigns)

    I’ve figured it out. If you don’t have the “Views” plugin as well, you have to go this route:

    $args = array(
    'numberposts' => 1,
    'order'=> 'ASC',
    'post_mime_type' => 'image',
    'post_parent' => $post->ID,
    'post_type' => 'attachment'
    );
    
    $get_children_array = get_children($args,ARRAY_A); //returns Array ( [$image_ID]...
    $rekeyed_array = array_values($get_children_array);
    $child_image = $rekeyed_array[0];

    Then you need to use the types_render_field call along with the
    $child_image[‘post_title’] to set the title and alt tags:

    echo types_render_field("mdis_tip", array("output"=>"html","size"=>"footer-tip", "alt" => $child_image['post_title'], "title" => $child_image['post_title']));

    Plugin Author Amir Helzer

    (@amirhelzer)

    This is certainly a valid solution.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Types – Custom Fields and Custom Post Types Management] Adding Alt and Title Text to Custom’ is closed to new replies.