Toolset Types
[resolved] [Plugin: Types - Custom Fields and Custom Post Types Management] Adding Alt and Title Text to Custom (3 posts)

  1. klongdesigns
    Posted 4 years ago #

    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.


  2. klongdesigns
    Posted 4 years ago #

    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']));

  3. Amir Helzer
    Plugin Author

    Posted 4 years ago #

    This is certainly a valid solution.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Toolset Types
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic