WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. jsing
    Member
    Posted 1 year 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>
    <?php
    // Find connected customers
    $connected = new WP_Query( array(
      'connected_type' => 'posts_to_customers',
      'connected_items' => get_queried_object(),
      'nopaging' => true,
      'connected_meta' => array(
    	array(
              'key' => 'customertype',
    		'value' => $customertype,
               )
            )
    
    ) );
    
    // Display connected customers
    if ( $connected->have_posts() ) :
    ?>
    <ol>
    <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
    	<li><a href="<?php the_permalink(); ?>"> <?php the_title();?> </a>
    </li>
    <?php
    $answer = p2p_get_meta($post->p2p_id, 'customertype', true);
    echo $answer;
    ?>
    <br/> 
    
    <?php endwhile; ?>
    </ol>
    
    <?php
    // Prevent weirdness
    wp_reset_postdata();
    
    endif;
    ?>

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 1 year 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

About this Topic