Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Posts2Posts -- can't get connection title
<?php
global $post;
$connections = P2P_Connection_Type_Factory::get_all_instances();
if (!empty($connections)) {
foreach ($connections as $type => $conn) {
p2p_connection_box($type, $conn, $post);
}
}
function p2p_connection_box($type, $conn, $post) {
$direction = false;
$opposite = false;
if ($conn->side['from']->query_vars['post_type'][0] == $post->post_type) {
$direction = 'from';
$opposite = 'to';
} else if ($conn->side['to']->query_vars['post_type'][0] == $post->post_type) {
$direction = 'to';
$opposite = 'from';
}
$opposite_post_type = $conn->side[$opposite]->query_vars['post_type'][0];
if ($direction) {
?>
<li>
<h3 class="widgettitle">
<?php
echo $conn->get_field('title', $direction); // empty string
// in version 1.4.2 I would get the box title using:
// echo $conn->title[$direction];
?>
</h3>
<!-- some more markup goes here -->
</li>
<?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment