Support

Account

Home Forums Front-end Issues Options Page Post Object field post on category.php

Unread

Options Page Post Object field post on category.php

  • Have you ever experimented with using the post object field on the options page to show post data on a category page?

    I have been trying my best to somehow show fields from the queried post object, but I cannot seem to get it.

    Here is the code from my category.php file:

    
    <?php
    
                // get the current taxonomy term
                $term = get_queried_object();
    
                $post_object = get_field('dist_feat_posts_01', $term);
    
                if ($post_object):
    
                    // override $post
                    $post = $post_object;
                    setup_postdata($post);
    
                    $image = get_field('square_image', $term);
                    echo '<pre>';
                        var_dump($image);
                    echo '</pre>';
                    ?>
    			    <div>
    					<img src="<?php the_field('square_image'); ?>">
    
    			    	<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    			    	<span>Post Object Custom Field: <?php the_field('square_image', $post_object->ID); ?></span>
    			    </div>
    			    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly?>
    			<?php endif; ?>
    

    dist_feat_posts_01 = return format, Post Object
    square_image = return value, Image Array

    Feeling pretty lost 🙂
    Any help is greatly appreciated.
    -Luke

Viewing 1 post (of 1 total)

The topic ‘Options Page Post Object field post on category.php’ is closed to new replies.