WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Default value for 'fields' (4 posts)

  1. daniel_not_dan
    Member
    Posted 2 years ago #

    I'm building a personal movie database - this plugin is working awesomely for me and I'm having a lot of fun playing around with it.

    Here's my question:
    I've set it up so that I can assign a "strength of performance" indicator to a particular actor in a particular movie (using 'fields' where I've defined the movies-to-actors relationship in functions.php). I want to be able to see that Michael Caine was really good in Batman Begins, but not so great in Jaws 4, or whatever.
    I initially set it up to have two values: "great", and "same-old". However, in a movie like "Harry Potter" where there are a gazillion actors, it gets tedious setting most of them to "same-old". Is there a way to make a custom field default to a certain value unless I specify otherwise?

    I'm not super-strong on PHP, and I've played around a little trying to get it to work, but with no luck.

    Any ideas?
    Thanks!

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

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    You can do this in the development version (1.3-alpha3), like so:

    'fields' => array(
        'role_type' => array(
            'title' => 'Performance',
            'values' => array( 'great', 'same-old' ),
            'default' => 'same-old'
        ),
    ),
  3. letusrise
    Member
    Posted 2 years ago #

    @scribu Wow, I've been waiting for this feature. :D

  4. jsing
    Member
    Posted 2 years ago #

    How can this data be displayed? Here is what i have:

    /* Register connection */
    function svrn_connection_type() {
        $connection_args = array(
    
    'name' => 'posts_to_customers',
            'from' => 'post',
            'to'   => 'customer',
    
                'fields' => array(
                    'type' => array(
                        'title' => __('Type', 'svrn'),
                        'values' => array(
                            'purchase' => __('POS', 'svrn'),
                            'pawn' => __('Pawn', 'svrn'),
    			'vendor' => __('Vendor', 'svrn'),
    			'sale' => __('Sale', 'svrn')
                        	),
                    )
                )
    
        );
    
        p2p_register_connection_type($connection_args);
    }
    
    add_action( 'init', 'svrn_connection_type' );

    Which works great. For getting the name of the customer I have been using:

    <?php
    // Find connected customers
    $connected = new WP_Query( array(
      'connected_type' => 'posts_to_customers',
      'connected_items' => get_queried_object(),
      'nopaging' => true,
    ) );
    
    // 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><br/>
    <?php echo p2p_get_meta($post->p2p_id, 'type', true );?>

    I only get the title of the post but not the Type.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic