Inserting Custom Field Contents into Tab Post Content

Bring Your Business to LifeSupportPopular WidgetInserting Custom Field Contents into Tab Post Content

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #55290
    Xpark Media
    Keymaster

    @buegelfrei,

    if you want to add content or replace the title on a particular tab using the “pop_{$this->current_tab}_title” filter.

    this is how you use it

    function add_replace_title_on_post_tab( $title ){
    $title . "add something after the title";
    return $title;
    }add_filter( 'pop_recent_title', 'add_replace_title_on_post_tab' );

    or you can replace the entire content using the “pop_recent_posts_content” filter.

    #55301
    buegelfrei
    Participant

    I must be doing something wrong: just working with your starter code, I would expect to see each title get “add something after the title” added to it. Instead, the titles are gone altogether under the “Recent” tab. (The titles are still there under Popular and Commented, the other two tabs that I’m using).

    I’ve got this at line 382 in functions.php:

    function add_replace_title_on_post_tab( $title ){
    $title . "add something after the title";
    return $title;
    }

    And this at the last line of the file:
    add_filter( 'pop_recent_title', 'add_replace_title_on_post_tab' );

    Thanks!

    #55311
    buegelfrei
    Participant

    I think I just figured out how to do it. I’ll post my solution here, if it works…

    #55325
    Xpark Media
    Keymaster

    Here are other filters

    • pop_recent_title
    • pop_commented_title
    • pop_viewed_title

    Try this code

    function add_replace_title_on_post_tab( $title ){
    return $title . "add something after the title";
    } add_filter( 'pop_recent_title', 'add_replace_title_on_post_tab' );
    #55339
    buegelfrei
    Participant

    Solved!

    It seems that the plugin I was using to create my custom field was the culprit. Once I realized that WP had custom field functionality already built in, I found that adding the following to display_post_tab_content was all I needed to display a WP-generated custom field in tab post content:

    $output .= 
    '<span class="myClass">'. get_post_meta($post->ID, 'myCustomField', true) . '</span> ';

    (My solution did not work for the custom field created via the plugin which shall remain nameless. Disabled and deleted!)

    Thanks again for Popular Widget!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.