Support » Plugin: Pods - Custom Content Types and Fields » automatically attach Term Image to Single Recipe Post

  • Resolved Gamicord

    (@gamicord)


    Hello Sir,
    I’m trying to do something, but can’t even think of the remotest way to do it.

    I created a Custom Post Type called Recipe. This Recipe Post Type has 9 Subterms or Subcategories which are: Main Dish, Side Dish, Snacks, and so on.

    Now, I added a Field called Recipe Image to Recipe(the Post Type). Then if I go to edit Main Dish, or Side Dish, or Snacks (which are Terms/children of Recipe Post Type), they all had the Recipe Image Field: of which I’ve entered an image for each one of them.

    When creating a Single Recipe, the field “Recipe Image” is visible, then I choose a Recipe Image and also choose the Term that this Single Recipe should belong to. For example I choose Main Dish as the Term that this newly created Recipe belongs to. And Main Dish Term already has an image assigned to it.

    But when creating with Elementor and I query Recipe Image, it doesn’t load any image for the Single Recipe.

    However, if I add the Recipe Image on a Post by Post basis, during the Recipe creation process, a Recipe Image loads. It loads to give me something like this (https://prntscr.com/1b4omnc).

    Now, it’s very stressful to be adding Recipe Image on every Recipe creation process.

    Couldn’t it just pull the image attached to the Term since the Recipe already belongs to the Term, and the Term already has an assigned Image?

    How do I set it up, so that once I’ve assigned an image to a Term, it automatically pulls an Image and attaches it to the Single Recipe based on the Term the Recipe belongs to?

    Needing to hear from you soon.

    Regards.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Paul Clark

    (@pdclark)

    You can use the Elementor shortcode widget for this.

    The following, if added to a plugin or your theme’s functions.php, will add a shortcode [mealtimes_and_image] that displays custom fields image and background_color from taxonomy mealtime:

    <?php
    /**
     * Plugin Name: Recipe taxonomy images & labels
     * Description: Output a linked image and title from the <code>image</code> field on the <code>dish</code> taxonomy using shortcode <code>[mealtimes_and_image]</code>.
     */
    add_shortcode(
    	'mealtimes_and_image',
    	function( $a ) {
    		ob_start();
    		?>
    		<style>
    			.meal-wrapper {
    				position: relative;
    				display: inline-block;
    				width: 150px;
    			}
    			.mealtime-wrapper {
    				position: absolute;
    				top: 0;
    				right: 0;
    			}
    			.mealtime-wrapper a {
    				float:  right;
    				clear:  right;
    
    			}
    		</style>
    		<?php
    		echo '<div class="meal-wrapper">';
    
    		$terms = wp_get_post_terms( get_the_ID(), 'mealtime' );
    		foreach( (array) $terms as $term ) {
    			if ( ! empty( get_term_meta( $term->term_id, 'image', true )['ID'] ) ) :
    				echo wp_get_attachment_image(
    					get_term_meta( $term->term_id, 'image', true )['ID'],
    					'thumbnail'
    				);
    				break;
    			else :
    				continue;
    			endif;
    		}
    		echo '<div class="mealtime-wrapper">';
    		foreach( get_the_terms( get_the_ID(), 'mealtime' ) as $term ) {
    			echo '<a href="' . esc_url( get_term_link( $term ) ) . '">';
    			echo '<div style="background-color: ' . get_term_meta( $term->term_id, 'background_color', true ) . ';">';
    			echo $term->name;
    			echo '</div>';
    			echo '</a>';
    		}
    		?>
    		</div>
    		</div>
    		<?php
    
    		return $c . ob_get_clean();
    	}
    );
    
    Plugin Support Paul Clark

    (@pdclark)

    Thread Starter Gamicord

    (@gamicord)

    Hello Sir,
    You have given me two(2) codes. Two powerful PHP codes for that matter. Something that I can’t even write the first line of.

    Unfortunately, I’ve applied them, but they’ve not worked, nor have they given me my expected result.

    I added the shortcode. See it here– https://prntscr.com/1bahgv2

    But on the frontend, it didn’t appear. See it here– https://prntscr.com/1banors

    It is at this point that I am believing that the reason could be a lack of understanding between us. I am believing that you presume to understand what I want, but may be getting a vague picture of it.

    I therefore thought of asking you, that can we take it step by step?

    And this means a number of things:

    1.) I tell you what I’ve done, I tell you what is remaining, and you take it up from there.

    or

    2.) You try to understand what I want. Then you come into my system to see that it’s implemented.

    Can we do it this way Sir?

    The reason I am looking at the 2 propositions above, is because I feel you are kind of aloof, and are helping me with only a vague picture in mind of what you suppose I’m asking.

    Whereas, I feel that if you get closer to my problem and do have a closer look, and investigate my system and set up that I’ve done, I believe we could have a headway.

    Can we do it like that Sir?

    Needing to hear from you soon.

    regards

    Plugin Support Paul Clark

    (@pdclark)

    It’s getting a bit late here to set it up in your environment, but if you can join the #support channel at https://support.pods.io/chat/ then we may be able to do something quickly.

    Thread Starter Gamicord

    (@gamicord)

    I’m presently on Slack now. What do I do next?

    Plugin Author Jory Hogeveen

    (@keraweb)

    Closing topic since it moved to Slack.

    Cheers, Jory

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.