WordPress Custom Related Posts: Toolset Plugin & Posts 2 Posts – Combining APIs for even more flexibility

Four Eyes PHP, Web Design, Web Development, Wordpress, WP-Toolset

WordPress Custom Related Posts, this is one of the biggest issues; creating a custom related post with a custom formatted layout. Even to a seasoned developer this is a complicated and time-consuming endeavor.  In the past, we have used tools like Toolset, but even this had its limitations. The Toolset approach is to link to post types via a third post type that linked the other two types.  This is an easy concept if you understand data relationships, however, it made a three step process and it is not very efficient. Here is a direction to take!

Four Eyes is currently working on a new website for David Keil’s YogAnatomy.com.  The current website, built by Four Eyes, is a rich combination of  web design and web development approaches to enhance the user’s experience.  The new website, to be launched soon, will take this vision further.   YogAnatomy.com needed a method for connecting content types to one another in an easy  and efficient manner.  We knew of the tools we wanted to use and now it was time to get them talking to one another.

toolset-logo1Toolset is a powerful plugin with a corresponding set of APIs that enables a web developer to create custom post types and layouts in WordPress well beyond the standard title and body defaults.  Toolset‘s claim to fame is that it lets “you create anything from brochure sites to advanced e-commerce and directory sites, without writing a single line of PHP”.  This is true.  However, having extensive knowledge of CSS, JavaScript, HTML, AJAX and Programming knowledge for logic structures makes this plugin a lot more powerful than what comes out-of-the-box.  Four Eyes is  a Toolset certified partner & consultant.  Toolset is a standard part of our development tools and we are hired by many other web design agencies to handle Toolset integration.  We love this plugin.  Once you setup a custom post type via their user interface, you can develop a loop and single page layouts using HTML and shortcodes, for example:

The Posts 2 Posts plugin allows you to create many-to-many relationships between posts of any type (post, page, custom etc.). The plugin is not actively managed any longer, but, it is rock solid. The plugin does not have a user interface.  It requires you to register your post connections in your functions.php file. For example,

function my_connection_types() {
p2p_register_connection_type( array(
'name' => 'posts_to_pages',
'from' => 'post',
'to' => 'page'
) );
}
add_action( 'p2p_init', 'my_connection_types' );

ishot-46Granted to the novice, this can look daunting, but the hook is straight forward.  Once hooked in, the Posts 2 Posts plugin displays an easy to use interface on the post admin page.  You can select one or more the related posts that you would like to insert.  Drag & drop is available for sorting.  For all of our projects, we use custom post types and custom fields and the plugin works great.  Now that we have a custom post type, related content types, a view defined in Toolset and now we need to display them.

$connections = new WP_Query( array(
'connected_type' => 'what_are_we_connecting',
'connected_items' => get_queried_object(),
'nopaging' => true,
) );

if ( $connections->have_posts() ) :
while ( $connections->have_posts() ) : $connections->the_post();
$args = array(
'title' => 'Event Location',
'pid' => $post_id
);
echo render_view( $args );

endwhile;
wp_reset_postdata();
endif;

The above solution works great with integrating related content on single post pages.  Now onto figuring out a good direction for a loop!

Yes, I have simplified the code above, but if you check out the Posts 2 Posts plugin documentation and also the Toolset API it will fall into place.  Alternatively, call Four Eyes and we are happy to work with you!

 

Four Eyes builds custom WordPress websites for any business!
Contact us to learn more »