Posts 2 Posts
Using p2p_get_meta in widget sidebar (2 posts)

  1. jsing
    Posted 4 years ago #

    I am trying to list data using the Executable PHP Widget by Otto to display php in a sidebar. The code works fine in a page template but only returns the post title in the sidebar. I don't know if this has something to do with the PHP Widget plugin or P2P. Anyone have a suggestion on how to get it to work? Here is the code I am using:

    <h2>Customer Relationship</h2>
    // Find connected customers
    $connected = new WP_Query( array(
      'connected_type' => 'posts_to_customers',
      'connected_items' => get_queried_object(),
      'nopaging' => true,
      'connected_meta' => array(
              'key' => 'customertype',
    		'value' => $customertype,
    ) );
    // Display connected customers
    if ( $connected->have_posts() ) :
    <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
    	<li><a href="<?php the_permalink(); ?>"> <?php the_title();?> </a>
    $answer = p2p_get_meta($post->p2p_id, 'customertype', true);
    echo $answer;
    <?php endwhile; ?>
    // Prevent weirdness


  2. scribu
    Plugin Author

    Posted 4 years ago #

    My guess is that you have to add global $post at the top of that code, but I could be wrong.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Posts 2 Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic