• Dear community,

    I started learning Pods and Elementor Pro as they seem to fit my cost needs best. But Iā€™m also up for the challenge to learn more.


    I created CPTs for Services and Projects, for which I created relationships ā€˜service-relationā€™.

    Now I built a single page template for Services in Elementor, and I would like that page to show only related projects in the loop carousel at the bottom of the page.

    What would be the custom query command and how to assign an Query ID to it in Code Snippets?

    Would anybody be willing to help me out? Iā€™d love to learn that also for my other project.

    Thanks a lot in advance!

    Cheers,

    Jonas

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi, there are a few ways to accomplish this using Elementor Pro and its Dynamic Tags. I’m using ACF free, but I suppose it is close to using PODs. Or at least you can take something from the methods I describe.

    If the relationship setup is not bidirectional Case 1 will work only on the CPT with attached related posts field to it. In other words, the posts that are related will not “know” they are related to something, hence you will not be able to display the relationship in them.

    Case 2 will work everywhere.

    For Case 1 you will need Advanced Post Queries Plugin, which extends Elementor Post Query options with some useful dynamic tag options.

    Case 1:

    • The easiest way is if you have bidirectional relationship set up on both post types (you can also have relationship only on the CPT you wish to display related posts to).
    • Then you just put the Carousel/Loop Grid widget, create a Loop Template to display the data you wish using Dynamic Tags (for example: image and title).
    • After in the Carousel/Loop Grid widget Query Setting you choose for source your CPT that has the custom relationship field.
    • In the Advanced Query Options that are now available (thanks to the Advanced Post Queries Plugin) you choose: – Dynamic Related Posts; In the Related Posts you choose – Post is in Current Post Custom Field.
    • In the Related Posts Field input: put the key of your relationship field in your case maybe it is: service-relation.

    That’s it. The Loop Grid will now pull the related posts for your CPT.

    Case 2:

    To use the custom query option in the Loop Grid/Carousel you must create, well custom query. You can do this by using Code Snippets Plugin for simplicity and granular control, or put the query code in your theme functions.php (a bit messy IMO).

    I give you an example of the query I’ve built for me:

    • In the example you must replace your_custom_query_name with whatever you’d like your query to be called (you will use this name later in the Custom Query input field of Elementor Post Grid widget)
    • You should also replace the relation_field_key with your custom field name /probably: service-relation/ so the query can get the related posts inputed in that field.
    // Create a custom query for Elementor based on the Relationship
    	add_action( 'elementor/query/your_custom_query_name', function( $query ) {
    		// Modify the posts query here
    		$meta_query = $query->get( 'meta_query' );
    		if ( ! $meta_query ) {
    		$meta_query = [];
    		}
    		$meta_query[] = [
    			array(
    				array(
    					'key' => 'relation_field_key', // name of your custom field
    					'value' => '"' . get_the_ID() . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
    					'compare' => 'LIKE'
    					 )
    				 )
    	];
    		$query->set( 'meta_query', $meta_query );
    		} );
    • After you created your custom query, you go back in Elementor to build your single post template.
    • Put the Carousel/Loop Grid widget, create a Loop Template to display the data you wish.
    • in the Carousel/Loop Grid widget Query Setting you choose for source your CPT that has the custom relationship field.
    • In the Carousel/Loop Grid widget Query Setting, in the Query ID field you just put your_custom_query_name

    Voila! That’s it, now the template for your single post type will display the posts put in the relationship field.

    I would love to see some other implementations. Hopefully I didn’t confused you ??

    Plugin Support Denny Paul

    (@thetechxpert)

    Hi,Since you are an Elementor Pro user, you can open a support ticket at my.elementor.com I’d also suggest you check out our Elementor Community forum, we have created it to connect Elementor users together and share knowledge, my.elementor.com. www.remarpro.com rules state that commercial products are not supported here.

    Thread Starter jonass1

    (@jonass1)

    Hi @ivelinjpashev ,

    Wonderful! Thank you so much for that! I didn’t get a chance to sit down on it and try it yet, but it looks like you hit the nail on it’s head! Really nice of you, thanks again so much! I’ll keep you posted about how I manage.

    @thetechxpert Thank you for you suggestion too! I did submit a ticket already too. I also tried the Elementor facebook group, but no luck yet. But I would like to also learn it myself, as I have another CPT of testimonials to still link to my projects too ??

    I will get to it later this week, already looking forward! Will keep you both posted.

    Cheers,

    Jonas

    • This reply was modified 1 year, 2 months ago by jonass1.
    Thread Starter jonass1

    (@jonass1)

    Hello again @ivelinjpashev ,

    I tried directly the Case 2 option, and it doesn’t work. It leaves the whole section blank, even though there are related projects attached to it.

    It seems it recognizes the custom query, but hides the entire carousel instead.

    I originally tried it with custom logic to only let it show projects that contain a field that is ‘equal’ or ‘contains’ the service, but the same thing happened – it hid the whole carousel section.

    I wonder then if this could indeed be a more concrete issue for Elementor support.

    Will keep you posted.

    Cheers,

    Jonas

    Thread Starter jonass1

    (@jonass1)

    [Update – Resolved]

    In the depths of Reddit I found the answer: https://www.reddit.com/r/elementor/comments/14h1vph/pods_relationship_fields_only_show_the_first_item/

    It’s a plugin, but it also works nicely with the Elementor Loop design!

    So, I’m happy, my services page now shows only related posts to the service. ??

    Thanks everyone for help anyways!

    Cheers,

    Jonas

    Exact same issue here. Case #1 from @ivelinjpashev does work but only shows the first item in the relationship, not multiple. Case #2 does not seem to work for PODS as it uses a custom database table (wp_podsrel) for their relationships, so this function would need to be modified.

    I’d love to try the Reddit plugin mentioned as the solution, but it seems they have stopped support for it recently and it can no longer be downloaded. @jonass1, is there any way to provide or DM the e-Query POSTS plugin files?

    @netzzjd I’m stuck with the exact same issue, I don’t want to rebuild everything with ACF because I like the PODS Plugin. Did you find a solution for this? This should be possible with the PHP code provided by @ivelinjpashev I think, maybe it’s just a small change for the PODS custom field?

    Thanks for the reply!

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