Support

Account

Home Forums Front-end Issues Using Post_Object only returning IDs?

Solved

Using Post_Object only returning IDs?

  • Hello, i have been grinding away non stop trying to setup a system soa custom post type that holds the game data can be selected and then displayed within other pages.

    I got very very close by using:

    <?php if ($variable = get_field('get_game_details', $post->ID) ): ?>
    <?php $post_object = get_field('get_game_details');
                        if( $post_object ): 
                            // override $post
                            $post = $post_object;
                            setup_postdata( $post ); 
                            ?>
                            <?php get_template_part( 'game_details', 'index' ); ?>
                            <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
                    <?php endif; ?>
    				<?php endif; ?>

    Template holds:

    <div id="game_details">	
    <?php if( get_field('game_title') ): ?>
       <div class="game_title">
       <a href="<?php the_permalink(); ?>"><?php the_field('game_title'); ?></a>
    </div><?php endif; ?>
    <?php if( get_field('retail_art') ): ?>
    <div class="retail_art">
    <?php
     
    /*
    *  Show selected image cropped to a specific size
    *  Return value = ID ( allows us to get more data about the image )
    *  This example uses the WP function: wp_get_attachment_image - http://codex.wordpress.org/Function_Reference/wp_get_attachment_image
    */
    $attachment_id = get_field('retail_art');
    $size = "small-thumb"; // (thumbnail, medium, large, full or custom size)
     
    $image = wp_get_attachment_image_src( $attachment_id, $size );
    ?>
    <img src="<?php echo $image[0]; ?>" /></div><?php endif; ?>
    
    <div class="game_details_container">
    <div class="key_information">
    <?php if( get_field('developer') ): ?>
    <p>Developer: <?php the_field('developer'); ?></p><?php endif; ?>
    <?php if( get_field('publisher') ): ?>
    <p>Publisher: <?php the_field('publisher'); ?></p><?php endif; ?>
    <?php if( get_field('system') ): ?>
    <p>System: <?php the_field('system'); ?></p><?php endif; ?>
    </div>
    <div class="release_dates">
    <?php if( get_field('uk_release_date') ): ?>
    <p>UK Release: <?php the_field('uk_release_date'); ?></p><?php endif; ?>
    <?php if( get_field('us_release_date') ): ?>
    <p>US Release: <?php the_field('us_release_date'); ?></p><?php endif; ?>
    <?php if( get_field('jap_release_date') ): ?>
    <p>Japan Release: <?php the_field('jap_release_date'); ?></p><?php endif; ?>
    </div> 		
    <?php if( get_field('game_series') ): ?>
    <div class="game_series"><p>Gaming Series:</p>
    <?php the_field('game_series'); ?></div><?php endif; ?>
    </div>
    <?php if( get_field('product_pitch') ): ?></div><?php endif; ?>
    <div id="product_pitch">
    <?php the_field('product_pitch'); ?>
    </div>
    <?php if( get_field('rating') ): ?>
    <div class="rating">
    <?php
    
    $field = get_field_object('rating');
    $value = get_field('rating');
    $label = $field['choices'][ $value ];
    /*
    *  Conditional statement (Single Value)
    */
     
    if(get_field('rating') == "pegi3")
    {
    echo '<img src="../ratings/ratings3.gif">';}
    elseif(get_field('rating') == "pegi7")
    {
    echo '<img src="../ratings/ratings7.gif">';}
    elseif(get_field('rating') == "pegi12")
    {
    echo '<img src="../ratings/ratings12.gif">';}
    elseif(get_field('rating') == "pegi16")
    {
    echo '<img src="../ratings/ratings16.gif">';}
    elseif(get_field('rating') == "pegi18")
    {
    echo '<img src="../ratings/ratings18.gif">';}
    ?></div><?php endif; ?>
    <?php if( get_field('descriptors') ): ?>
    <div class="descriptors">
    <?php
    $field = get_field_object('descriptors');
    $value = get_field('descriptors');
    $label = $field['choices2'][ $value ];
    
    if( in_array( 'drugs', get_field('descriptors'))){
    echo '<img src="../ratings/ratings_drugs.gif">';
    }else ;{
     }
    if( in_array( 'fear', get_field('descriptors'))){
    echo '<img src="../ratings/ratings_fear.gif">';
    }else ;{
     }
    if( in_array( 'discrimination', get_field('descriptors'))){
    echo '<img src="../ratings/ratings_discrim.gif">';
    }else ;{
     }
    if( in_array( 'swearing', get_field('descriptors'))){
    echo '<img src="../ratings/ratings_lang.gif">';
    }else ;{
     }
    if( in_array( 'gambling', get_field('descriptors'))){
    echo '<img src="../ratings/ratings_gamble.gif">';
    }else ;{
     }
    if( in_array( 'violence', get_field('descriptors'))){
    echo '<img src="../ratings/ratings_violence.gif">';
    }else ;{
     }
    if( in_array( 'nudity', get_field('descriptors'))){
    echo '<img src="../ratings/ratings_nudity.gif">';
    }else ;{
     }
    if( in_array( 'sex', get_field('descriptors'))){
    echo '<img src="../ratings/ratings_fsex.gif">';
    }else ;{
     }
    if( in_array( 'online', get_field('descriptors'))){
    echo '<img src="../ratings/ratings_online.gif">';
    }else ;{
     }
    ?></div><?php endif; ?>
    </div>

    However the terms returned are displayed as:

    47

    Developer: 48

    Publisher: 49

    System: 46

    UK Release: 11 Oct 2013

    US Release: 11 Oct 2013

    Japan Release: 11 Oct 2013

    Gaming Series:
    64

    I have spent all weekend building custom post types and Toxonomys as it is my first ever time. Once I am able to pull data from other pages correctly I am pretty much sorted. Addon is amazing and saved me alot of time. Thank You.
    `

  • Hi @matthew O’Donnell

    In your first snippet of code, you are using 2 different lines of code to do the same thing:

    
    <?php if ($variable = get_field('get_game_details', $post->ID) ): ?>
    <?php $post_object = get_field('get_game_details');
    

    The first line sets $variable to that of the posts from a specific post_id, however, you then store $post_objects from the current post_id (no parameter).

    Is this a mistake or intentional?

  • No was a total error. Been grinding for 3 days with zero luck getting data. Put messy code together just to show it to find out why only ID’s where called. Just updated with you recommended document code again.

    <?php $post_object = get_field('get_game_details');
    if( $post_object ): 
    	// override $post
    	$post = $post_object;
    	setup_postdata( $post ); ?>
            <?php get_template_part( 'game_details', 'index' ); ?>
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>

    However I still cannot figure out why only ID's are called and not the display of the data.
    For Example – 47 = Pokemon X & Y

    To further explain. When viewed from normal post type all data is fully visible. However when viewed from my custom post type 'Games Information' (that also uses custom Toxonomys), all the data is simple ID's.

    add_action( 'init', 'register_cpt_game_information' );
        function register_cpt_game_information() {
        $labels = array(
        'name' => _x( 'Games Information', 'game_information' ),
        'singular_name' => _x( 'Game Information', 'game_information' ),
        'add_new' => _x( 'Add New', 'game_information' ),
        'add_new_item' => _x( 'Add New Game Information', 'game_information' ),
        'edit_item' => _x( 'Edit Game Information', 'game_information' ),
        'new_item' => _x( 'New Game Information', 'game_information' ),
        'view_item' => _x( 'View Game Information', 'game_information' ),
        'search_items' => _x( 'Search Games Information', 'game_information' ),
        'not_found' => _x( 'No games information found', 'game_information' ),
        'not_found_in_trash' => _x( 'No games information found in Trash', 'game_information' ),
        'parent_item_colon' => _x( 'Parent Game Information:', 'game_information' ),
        'menu_name' => _x( 'Games Information', 'game_information' ),
        );
        $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
        'taxonomies' => array( 'category', 'post_tag' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
        );
        register_post_type( 'game_information', $args );
        }
    add_action( 'init', 'register_taxonomy_game_title' );
        function register_taxonomy_game_title() {
        $labels = array(
        'name' => _x( 'Game Title', 'game_title' ),
        'singular_name' => _x( 'Games Title', 'game_title' ),
        'search_items' => _x( 'Search Game Title', 'game_title' ),
        'popular_items' => _x( 'Popular Game Title', 'game_title' ),
        'all_items' => _x( 'All Game Title', 'game_title' ),
        'parent_item' => _x( 'Parent Games Title', 'game_title' ),
        'parent_item_colon' => _x( 'Parent Games Title:', 'game_title' ),
        'edit_item' => _x( 'Edit Games Title', 'game_title' ),
        'update_item' => _x( 'Update Games Title', 'game_title' ),
        'add_new_item' => _x( 'Add New Games Title', 'game_title' ),
        'new_item_name' => _x( 'New Games Title', 'game_title' ),
        'separate_items_with_commas' => _x( 'Separate game title with commas', 'game_title' ),
        'add_or_remove_items' => _x( 'Add or remove game title', 'game_title' ),
        'choose_from_most_used' => _x( 'Choose from the most used game title', 'game_title' ),
        'menu_name' => _x( 'Game Title', 'game_title' ),
        );
        $args = array(
        'labels' => $labels,
        'public' => true,
        'show_in_nav_menus' => true,
        'show_ui' => true,
        'show_tagcloud' => true,
        'show_admin_column' => false,
        'hierarchical' => true,
        'rewrite' => true,
        'query_var' => true
        );
        register_taxonomy( 'game_title', array('game_information'), $args );
        }
  • To further expand:
    the ‘Taxonomy field’ is a select type field.
    So for exmaple a Toxonomy is made for a publisher. Post creation has a nice dropdown menu based on those Toxonomys.

    Any data that is stored in the Image/Date Picker/Text Area fields all display correctly.

    Only the Toxonomy Fields return Id’s and not the actual data.

    There are no documents explaining the purpose of the ‘Toxonomy Field’ or correct usage. But as far as seeing where the data IS it works fine. It just does not show the ACTUAL data itself 🙁

  • <?php if( get_field('developer') ): ?>
    <?php $args = array('taxonomy' => 'game_developer'); ?>
    <?php $tax_menu_items = get_categories( $args );
    foreach ( $tax_menu_items as $tax_menu_item ):?>
    <p>Developer:<a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"> <?php echo $tax_menu_item->name; ?></a></p>
    <?php endforeach; ?><?php endif; ?>
    

    Got it working with above code 😀 Now few tweaks and full steam ahead.

  • <?php if( get_field('system') ): ?>
    Systems: <?php echo get_the_term_list( $post->ID, 'game_system'); ?></a>
    <?php endif; ?>

    Even simpler for single target links… Why couldnt i solve this days ago.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Using Post_Object only returning IDs?’ is closed to new replies.