• Resolved austone

    (@austone)


    I have created a pod (custom post type named ‘recipe’) with repeater fields (each field is a step in the food preparation process).

    I have built an Elementor Single Page template for my recipe post type, and I’m trying to display the repeater fields (the preparation steps) using the Elementor Widget called ‘Pods – List Items’.

    I have created a template and everything seems to work fine, but this:
    Instead of showing the repeater fields of the current recipe only, ‘Pods – List Items’ shows all of the repeater fields for all the recipes in the website altogether.

    How can it be solved?
    Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Coding Panda

    (@codingpanda)

    @austone

    I don’t have much experience with Elementor, but I will try to solve the problem.

    I don’t have an Elementor Pro so I can’t build an Elementor Single Page template, but I can still use ‘Pods – List Items’ on normal pages. If I understand it correctly, you still have to create a template to display the repeater fields of the current recipe. Could I have the part of your code to display the repeater fields?

    Thread Starter austone

    (@austone)

    Hi, and thank you.

    I’m using the following code in the ‘Pods – List Items’ widget to create a sort of a table:

    <tr>
    <td>{@step_order}</td>

    <td>{@ingredients_for_this_step}</td>
    <td>{@how_to_prepare_this_step}</td>

    </tr>

    I guess that I have to somehow specify in the code that I mean to show all the repeater fields that belong to the specific recipe only (each recipe is obviously displayed alone in its web page, no more than 1 recipe in a single webpage).

    Thanks!

    Plugin Author Coding Panda

    (@codingpanda)

    Hi @austone

    I’m struggling to replicate what you are doing. would you please use Pods’ Migrate: Packages component to export the relevant pods for me so I can test it on my computer?

    Thanks

    Thread Starter austone

    (@austone)

    Sorry for the delay.
    Thank you for trying to solve this.
    Please see the attached file for the pods data I exported:

    https://drive.google.com/open?id=1rwBrHkBPUff2AYlTNN5MRguP-nl2znCJ

    Plugin Author Coding Panda

    (@codingpanda)

    Hi @austone

    Thanks for exporting the Pods for me. This is not a problem with the plugin but I have found a solution for you. This is the background knowledge for the solution: https://docs.pods.io/displaying-pods/magic-tags/display-filters-with-magic-tags/

    Here are the screenshots:
    Input
    https://www.dropbox.com/s/xp85v47btdqnkiz/Elementor%20recipe%282%29.png?dl=0

    Output
    https://www.dropbox.com/s/p6ed6wpg1fbrrck/Second%20recipe%20%E2%80%93%20Panda%20Pods%20Repeater%20Field%281%29.png?dl=`

    We are going to use magic tags in the “where” field to display the cooking process only for the current recipe, ?so first, we need to know the post id. Unfortunately, we cannot simply use get_the_ID() function as IDs are not available when functions.php is loaded, so we need to create a function to do it. This is the function I created. Hopefully, it also works for you.

    function return_post_id() {
    	
    	$url_parts = explode( '/', rtrim( $_SERVER['REQUEST_URI'], '/') );
    	
    	$slug = $url_parts[ count( $url_parts ) - 1 ];
    	$page = get_page_by_path( $url_parts[ count( $url_parts ) - 1 ], OBJECT, 'recipe');
    	
    	if( $page ){
    		return $page->ID;
    	} 
    	return false;
    
    }

    Save the function into functions.php, and save this into the “Where” field: pandarf_parent_post_id ={@post_id,return_post_id}.

    (If you use the step_in_cooking_process table as a repeater field somewhere else, you will need to add pandarf_parent_pod_id and pandarf_pod_field_id to the WHERE query.)

    Please let me know if this solution solves your problem.

    Thread Starter austone

    (@austone)

    You are truly the best.
    Thank you for your effort in helping me out. I appreciate that greatly.

    I did as you instructed:

    1. Added the longer code snippet to the theme’s functions.php
    2. Added the pandarf_parent_post_id code snippet to ‘Where’ in PODS-LIST ITEMS element in Elementor.

    Unfortunately, I don’t see any data.
    I tried reading through the link you provided. I think I could understand the concept but not the details, as I don’t understand any code.

    It seems that your solution worked on your end. Could there be anything else to check?

    Here are 2 screenshots:
    https://drive.google.com/file/d/15PXgSNrZkZwFnxGtB-6xR4InD1bckYy7/view?usp=sharing
    https://drive.google.com/file/d/15DslSY2R2ufYFybEIpDQZrMy4KMcFOXP/view?usp=sharing

    Thank you!

    Plugin Author Coding Panda

    (@codingpanda)

    @austone Would you try to run this function return_post_id() in functions.php, open one of your recipe pages and see if it prints out the page ID?

    Thread Starter austone

    (@austone)

    Hi,
    I added the line return_post_id(); in functions.php and opened one of the recipe pages, but could not see the page ID printed anywhere.

    Where should I look for it?
    On the webpage itself?

    Thanks again.

    Plugin Author Coding Panda

    (@codingpanda)

    Did you echo it out?
    echo return_post_id();

    If you view the recipe page at the frontend, you should see a number on the top. If it is 0 or nothing, then the function is not returning the page id.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘‘Pods – List Items’ Elementor widget displays all repeater fields on website’ is closed to new replies.