• Resolved Preston

    (@firebot)


    I currently have the Custom Field Template plugin (https://www.ads-software.com/extend/plugins/custom-field-template/) installed, and have added a field to pages where the user can enter custom text which will appear in the title attribute of the menu anchor tags. Then (via jQuery) will be pulled into a fancier tooltip.

    What I’m having trouble with is adding the custom field to my get_pages setup. I’m using this method: https://www.ads-software.com/support/topic/plugin-custom-field-template-insert-custom-code-into-a-template?replies=9 to allow me to put the custom field entries into my templates. It’s working fine when I add it in anywhere else on the page.

    Below is my get_pages code, which is located in my header.php file (based on an example from the get_pages wiki page).

    <?php
    $pages = get_pages();
    foreach ( $pages as $pagg ) {
    $menuList = '<li><a href="' . get_page_link( $pagg->ID ) . '" title="' . getCustomField('Tooltip Text') . '">';
    $menuList .= $pagg->post_title;
    $menuList .= '</a></li>';
    echo $menuList;
    }
    ?>

    With this setup, the custom field text is not appearing within the title attribute, but rather outside of the anchor tag and list tags all together. It also showing the custom field text for the current page in all instances, instead of the custom field text for each individual page (regardless of what the current page is).

    If I delete ' . getCustomField('Tooltip Text') . ' and just enter Testing instead, it display as expected (inside the title attribute, which jQuery moves to a tooltip).

    I’m a novice at PHP, so I have a feeling I’m missing something simple. At least, I hope it’s simple!

    I appreciate any help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • the getCustomField function does not get the data from the pages, but from the global $post object;

    you might need to rewrite the function to use a page ID or so as second parameter.

    or simply use naked code such as:

    get_post_meta($pagg->ID, 'Tooltip Text')

    instead of:

    getCustomField('Tooltip Text')

    Thread Starter Preston

    (@firebot)

    Thanks, that got me in the right direction.

    get_post_meta($pagg->ID, 'Tooltip Text', true) works well, except it makes all capital letters lower case. I’m not sure if it’s related to this or something else.

    Using only get_post_meta($pagg->ID, 'Tooltip Text') just returned “array” from all of the fields, regardless of what was in them.

    Thread Starter Preston

    (@firebot)

    The all lowercase letters was CSS related (a thought lapse on my part). So everything is working great. Thanks again!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_pages with Custom Field Template plugin filling title attribute’ is closed to new replies.