{"id":6513,"date":"2022-09-27T15:21:31","date_gmt":"2022-09-27T13:21:31","guid":{"rendered":"https:\/\/mainetcare.de\/?post_type=techdoc&#038;p=6513"},"modified":"2026-07-14T11:35:16","modified_gmt":"2026-07-14T09:35:16","slug":"fill-elementor-posts-widget-with-acf-related-field","status":"publish","type":"gartenschuppen","link":"https:\/\/mainetcare.de\/en\/gartenschuppen\/elementor-beitraege-widget-mit-acf-beziehungsfeld-fuellen\/","title":{"rendered":"Fill Elementor posts widget with ACF relationship field"},"content":{"rendered":"<p>With the posts widget in Elementor, you can easily display other posts, pages, products or custom post types (CPT) (= user-defined content types) on a page in a loop. It only gets tricky if you want to display the content of a meta field, e.g. an ACF relationship field.<\/p>\n<p><strong>Problem:<\/strong><\/p>\n<p>The option offers ACF relationship in post widget does not offer Elementor.<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<ol>\n<li>ACF relationship field (e.g. field name \"<strong>my_acf_relationship_field<\/strong>\") on the desired page or content type and fill it with data.<\/li>\n<li>In Elementor, drag the \"Posts\" widget to the desired location<\/li>\n<li>Elementor settings: Source: -&gt; Content type<\/li>\n<li>Query ID: Enter an individual ID, e.g. \"<strong>acf_relation<\/strong>&#8220;<\/li>\n<li>All content types now appear in the preview, which we will now change.<\/li>\n<li>Save and exit Elementor Editor<\/li>\n<li>functions.php (Note: Only work on the child theme!). The following code changes the WP_Query object of Elementor:<\/li>\n<\/ol>\n<pre>add_action( 'elementor\/query\/<strong>acf_relation<\/strong>', function ( WP_Query $query ) {\r\n   $ids = get_field('<strong>my_acf_relationship_field<\/strong>', get_the_ID());\r\n   $query-&gt;set( 'post__in', $ids );\r\n   $query-&gt;set( 'orderby', 'post__in' );\r\n} );<\/pre>\n<p>The selected relationships should now be displayed in the same order as they appear in the ACF relationship field.<\/p>","protected":false},"featured_media":0,"template":"","meta":{"_acf_changed":false},"class_list":["post-6513","gartenschuppen","type-gartenschuppen","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/mainetcare.de\/en\/wp-json\/wp\/v2\/gartenschuppen\/6513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mainetcare.de\/en\/wp-json\/wp\/v2\/gartenschuppen"}],"about":[{"href":"https:\/\/mainetcare.de\/en\/wp-json\/wp\/v2\/types\/gartenschuppen"}],"wp:attachment":[{"href":"https:\/\/mainetcare.de\/en\/wp-json\/wp\/v2\/media?parent=6513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}