WordPress.org

Ready to get started?Download WordPress

Forums

Ambrosite Next/Previous Post Link Plus
[resolved] custom meta key value (6 posts)

  1. offpeakdesign
    Member
    Posted 2 years ago #

    a php novice trying to figure out how to do the following:

    Add meta key 'Work' to show in the previous and next loop.

    For example, if my meta key is Work and the value is numeric ie., '44'
    and my post title is 'Sample Title'

    So on the post where the next and previous links are, it shows:

    Next: Work 44 Sample Title

    Can this plugin do this?

    http://wordpress.org/extend/plugins/ambrosite-nextprevious-post-link-plus/

  2. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    Yes, that is possible if you are doing a custom sort on the 'Work' meta key (which I assume you are). The function call would look something like this:

    next_post_link_plus( array('order_by' => 'custom', 'meta_key' => 'work', 'link' => 'Next: Work %meta %title', 'format' => '%link') );

  3. offpeakdesign
    Member
    Posted 2 years ago #

    Thank you! That was what I was looking to do.

    I'm hoping you could help me just a little bit more.

    My original nav code looks very different to me and I'm not sure how to integrate it with what you've shared. I want to keep the original formatting, but to insert the 'work' meta key just before the post title with a dash in between.

    Here's the original code:

    <?php previous_post_link( '<div class="previous">' . __( '%link', 'hatch-pro' ) . '</div>', '<span class="post-nav-text">← Previous:</span> %title' ); ?>
    <?php next_post_link( '<div class="next">' . __( '%link', 'hatch-pro' ) . '</div>', '<span class="post-nav-text">→ Next:</span> %title' ); ?>
  4. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    Try this:

    <?php previous_post_link_plus( array('order_by' => 'custom', 'meta_key' => 'work', 'link' => '<span class="post-nav-text">? Previous:</span> Work %meta - %title', 'format' => '<div class="previous">' . __( '%link', 'hatch-pro' ) . '</div>') ); ?>
    <?php next_post_link_plus( array('order_by' => 'custom', 'meta_key' => 'work', 'link' => '<span class="post-nav-text">? Next:</span> Work %meta - %title', 'format' => '<div class="next">' . __( '%link', 'hatch-pro' ) . '</div>') ); ?>
  5. offpeakdesign
    Member
    Posted 2 years ago #

    genius. Thank you thank you thank you.

  6. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    I assume it worked then. :) Would you be so kind as to mark this thread resolved?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic