Elementor posts widget fill with ACF relationship field

With the posts widget in Elementor, you can easily display other posts, pages, products or custom post types (CPT) on a page in a loop. The only tricky part is when you want to display the content of a meta field, e.g. an ACF relationship field.

Problem:

The option offers ACF relationship in post widget Elementor does not offer.

Solution:

  1. ACF relationship field (e.g. field name "my_acf_relationship_field") on the desired page or content type and fill it with data.
  2. In Elementor, drag the "Posts" widget to the desired location
  3. Settings Elementor: Source: -> Content type
  4. Query ID: Enter an individual ID, e.g. "acf_relation
  5. In the preview, all content types now appear first, let's change that now.
  6. Save and exit Elementor Editor
  7. Edit functions.php (Note: Only work on the Child Theme!). The following code changes the WP_Query object of Elementor:
add_action( 'elementor/query/acf_relation', function ( WP_Query $query ) {
   $ids = get_field('my_acf_relationship_field', get_the_ID());
   $query->set( 'post__in', $ids );
   $query->set( 'orderby', 'post__in' );
} );

Now the correspondingly selected relationships should be displayed in the same order as they appear in the ACF relationship field.

See also

Shortcode E-Mail Obfuscator

The following shortcode snippet is useful for disguising emails to protect them from SPAM. Please note that this method only works if Javascript is activated. In addition, there is no 100%igen protection against bots,...

Elementor popup / flyout menu no longer closes for mobile view

Elementor: Version 3.72 Behaviour: An Elementor popup opens, but no longer closes (when clicking on icon or Esc or other triggers). If you look in the source code, you will find the Javascript error message: "Elementor t.entrance_animation_duration is undefined" Cause:...

PHPStorm: Local Changelist in Git Tool disappeared

Problem: Local Change List under PHPStorm is missing in the Git Tool Solution: From time to time I had the phenomenon that the Local Changelist (the files in my version control) were not visible as tabs in the Git tool....

Variable not available in blade component

Problem: The parameter transfer of a blade attribute does not work, the variable in the component is empty. There is no error message, but the variable does not appear to have been passed. Solution: The error may lie in the usage...

WP CLI Error: Error establishing a database connection.

Appearance: Submitting commands via WP CLI, but WordPress in the browser works. This error often occurs when the WP CL interpreter cannot correctly interpret the database connection in wp-config.php. Solution: In 99% of all cases the...

Convert Px to SEM / EM very quickly with Alfred

Auf dem Mac gibt es einen wunderbaren Alfred-Workflow, der Px in Rem umrechnet: Download Direktlink: https://raw.githubusercontent.com/vitorgalvao/requested-alfred-workflows/master/Workflows/Px%20Rem%20Em.alfredworkflow Einfach installieren, dann CMD-Space: Alfred Bar "pxrem" tippen und die Zahl in Pixel angeben. Die Umrechnung in REM wird…