• Hi,

    I am working completely inside the WP Admin and im trying to make the admin post edit screen display meta values for connected posts.

    I have two CPTs Recipes and Ingredients. I have a p2p connection from->recipes to->ingredients many-to-many. Ingredients have a meta box with a normal custom field ‘cost’.

    I want to list the meta value for cost on the recipe admin edit page in a meta box.

    I want to do something similar to this example from the p2p wiki but get the meta value for the post id. (not p2p meta, the normal WP post meta)

    <?php
    while( $connected->have_posts() ) : $connected->the_post();
        echo '<li>';
    
        the_title();
    
        // Display count and type
        echo '<br>';
        echo 'Count: ' . p2p_get_meta( get_post()->p2p_id, 'count', true );
        echo '<br>';
        echo 'Type: ' . p2p_get_meta( get_post()->p2p_id, 'type', true );
    
        echo '</li>';
    endwhile;

    can someone point me in the right direction?

    https://www.ads-software.com/plugins/posts-to-posts/

Viewing 1 replies (of 1 total)
  • Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    This seemed to do the trick: “get_post_meta( $post->ID”

    <?php
    
        $connected = new WP_Query( array(
        'connected_type' => 'recipes_to_ingredients',
        'connected_items' => get_queried_object(),
    
    ) );
    
    while( $connected->have_posts() ) : $connected->the_post();
    
        $cost = get_post_meta( $post->ID, 'foxware-ingredient-cost', true );
    
            echo '<li>';
    
            the_title();
    
            // Display cost
            echo '<br>';
             echo 'Cost: ' . $cost;
            echo '</li>';
    endwhile;
Viewing 1 replies (of 1 total)
  • The topic ‘display custom meta field key/value pair in connected post query’ is closed to new replies.