Inserting Custom Field Contents into Tab Post Content

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

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #55282
    buegelfrei
    Participant

    First, thanks for the great plugin. It seems to be working great on WP 3.7.1 and does 99% of what I want it to do.

    I’m working on a site for a client in which we have a custom text field (“department”) which produces a pre-headline which we show just above post titles on the blog. I’m trying to customize Popular Widget to show these pre-headlines in its tab post content.

    The following code works for me within theme files (e.g., loop.php, single.php):

    <?php $departments = get_post_meta( $post->ID, 'departments', true ); foreach( $departments as $department){ echo $department['department'];} ?>

    I have been trying to translate the above into something that works when spliced into display_post_tab_content in Popular Widget’s functions.php file, but without success.

    I would be grateful for any assistance.

    Mighty thanks!

    #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 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.