elementor / elementor

The most advanced frontend drag & drop page builder. Create high-end, pixel perfect websites at record speeds. Any theme, any page, any design.
https://elementor.com/
GNU General Public License v3.0
6.58k stars 1.42k forks source link

Getting Advanced Custom Fields to display on Elementor Posts Widget #5281

Closed onepoint0 closed 6 years ago

onepoint0 commented 6 years ago

Prerequisites

What problem is your feature request going to solve? Please describe. I would like to display Advanced Custom Fields in the Post Type widget ie,

----------------------------------------------------
| POST 1         | POST 2       | ... | POST N        |
----------------------------------------------------
| p1 title       | p2 title     | ... | pN title      |
| p1 content     | p2 content   | ... | pN content    |
| p1 meta        | p2 meta      | ... | pN meta       |
| p1 ACF         | p2 ACF       | ... | pN ACF        | 
| p1 ACF         | p2 ACF       | ... | pN ACF        | 
| p1 ACF         | p2 ACF       | ... | pN ACF        | 
----------------------------------------------------

Describe the solution you'd like In the post type widget have a section with a series of repeatable dynamic selects which allow you to select the ACF fields that you want to show on the posts that are output. EG a list of dropdowns like you have in the price list widget, but dynamic so that an ACF field can be selected from it. These fields are then displayed in posts that are output on the page.

Either this or store the ACF field name in its own element in the settings array so that it can be passed into the ACF's get_field function and the field can be displayed on the output.

Describe alternatives you've considered I can't find a way to do this without coding it. I've tried to code it by using the existing post type query code from the post widget and then adding some dynamic selects to get the ACF fields:

 $this->start_controls_section(
      'content_text_boxes',
      [
        'label' => __( 'Text Boxes', 'MMD-custom-elementor' ),
        'tab' => Controls_Manager::TAB_CONTENT,
      ]
    );

    $this->add_control(
      'text_1',
      [
        'label' => __( 'Choose Text 1', 'MMD-custom-elementor' ),
        'type' => Controls_Manager::TEXT,
        'dynamic' => [
          'active' => true,
        ],
        'default' => [
          'text' => 'Testimonial Copy',
        ],
      ]

  $this->end_controls_section();

Then in the render function, use the ACF get_field function to get the value of the field (this is pseudocode, as it doesn't work this way):

$fields = $this->get_settings_for_display();
$field1 = get_field( $fields['text_1'], get_the_ID() );
$field2 = get_field( $fields['text_2'], get_the_ID() );

The problem is I need to pass the field name into the first get_fields parameter but I can't easily get the field_name from the settings function without doing string manipulation on the embedded settings string:

    Array(
        [text_1] => 
        [text_2] => 
        [text_3] => 
            [__dynamic__] => Array (
                [text_1] => [elementor-tag id="4b54050" name="acf-text" settings="%7B%22key%22%3A%22field_5b613334e6e38%3Atestimonial_copy%22%7D"]
                [text_2] => [elementor-tag id="889d2b6" name="acf-text" settings="%7B%22key%22%3A%22field_5b613353e6e39%3Atestimonial_source%22%7D"]
                [text_3] => [elementor-tag id="1bde0d7" name="acf-text" settings="%7B%22key%22%3A%22field_5b613368e6e3a%3Atestimonial_date%22%7D"]
            )

I think string splitting the field name out of the settings might not always work or the array could change in later versions of Elementor. I can't find another place where the field name is stored. If the field name could be stored as its own array element it could easily be passed to the ACF function.

If this is the wrong angle or there is another way to do this, I would be happy to try that!

Additional context Add any other context or screenshots about the feature request here.

bainternet commented 6 years ago

@onepoint0

why not use the dynamic tags for ACF?

onepoint0 commented 6 years ago

HI @bainternet, thanks for the response. Do you mean just getting the value out of the settings with something like this:

echo $this->get_settings_for_display( 'text_1' ); echo $this->get_settings_for_display( 'text_2' ); echo $this->get_settings_for_display( 'text_3' );

I've tried that and it's getting the value of the correct ACF fields, but the value for the first post is being repeated on all of the posts, ie

| POST_1 | POST_2 | POST_2 | | ACF_P1_V1 | ACF_P1_V1 | ACF_P1_V1 | | ACF_P1_V2 | ACF_P1_V2 | ACF_P1_V2 | | ACF_P1_V3 | ACF_P1_V3 | ACF_P1_V3 |

As opposed to:

| ACF_P1_V1 | ACF_P2_V1 | ACF_P3_V1 |

I thought because of that the array is not designed to be used in this way.

Or do you mean something else altogether?

bainternet commented 6 years ago

something else altogether, https://youtu.be/DC7wlmHO8Lo?t=8m32s

onepoint0 commented 6 years ago

Yeh, that's exactly what I'm doing and it's not working for the post type widget.

onepoint0 commented 6 years ago

Hi @bainternet - could you help me with getting the values for each post? The values for the first post are printing on all posts on the page.

bkjproductions commented 6 years ago

Is this a request to have ACF repeatable fields available within Elementor? If so, add my vote! :) I see there are a number of fields available, but apparently the repeater is not. In my use case, I would like to create a repeatable set of dates/times for classes. I can add a single date but not a repeater that has multiple dates.

Below is a link to the fields that are supported by Elementor: https://docs.elementor.com/article/381-elementor-integration-with-acf

Turanligil commented 5 years ago

+1

IDESIGNSTUDIO commented 5 years ago

+1 it is very powerful if this feature will be added

We can build much reacher and better lists from food menus, immobile, services, offers, etc. anything that can be put in a list and has additional features that should be displayed as well

bart-prosite commented 5 years ago

+1 I really need this. Has anyone found an alternative solution?

dadequate commented 5 years ago

+1 This would be a great feature - in the meantime I found that dynamic.ooo post widget supports ACF (albeit has some quirks).

tdpt commented 5 years ago

Plugin (addon) AnyWhere Elementor Pro is also a good option until Elementor Pro enables editing the block layout in archive templates.

eznettools commented 5 years ago

Yes, maybe we can get a "dynamic" option in the "Meta Data" field. For example, I'm currently doing a real estate website with custom fields for "price", "sqft" "bedrooms", etc. I'd really like to add those fields to the posts widget.

Here's an image to help illustrate the idea...

example of intended result
margotmate commented 5 years ago

+1 Meanwhile, this free plugin is the answer: Elementor custom skin. It's perfect! https://wordpress.org/plugins/ele-custom-skin/

wasduman commented 5 years ago

+1 @margotmate you are a Lifesaver today. I would like to write beautiful words for you but I am out of time ;)

revr0t commented 4 years ago

@margotmate you are a rockstar

bloewe commented 4 years ago

Is there a way to apply the free version to custom post types?

AleksBaikalski commented 3 years ago

+1 That's strange it's still not possible

bkjproductions commented 3 years ago

I think this ticket was closed in error. The original request by @onepoint0 was to have the Posts WIDGET show custom fields. The video tutorial example given by @bainternet shows how to use ACF on a Post TEMPLATE. (Which is very nice and clear and beyond beta, at this point.)

The difference is that a Posts WIDGET would be an element on the page, that would loop through all Posts of a certain query, and within that loop print out the custom fields for each Post.

Unless there is some way to make a Post Template be a "style" output for the Posts Widget. That would be a really cool way to do it, things could be very modular that way. (That is, suppose the Posts Widget were extended so that instead of the pre-determined fields such as Post Author, Date, Title, Excerpt, you could indicate a Post Template for the styling and content of the data.)

Elementor Developers: Could you contact the creator of the Elementor Custom Skin plugin and purchase/licence/otherwise add it to the Pro version of Elementor?

ShamanFromSiberia commented 3 years ago

This ticket was definitely closed for no reason. The feature is still needed and should be accessible out of the box, not requiring 3rd-party solutions. +1

8BitSigdom commented 3 years ago

+1

Stml-St commented 2 years ago

@onepoint0

why not use the dynamic tags for ACF?

Because there are no dynamic Tags in the "Meta Data" - Field of the "Posts Widget"

fnook commented 1 year ago

I also have contacted Elementor support for the same issue this week. They sent me the details about the post template, which I've already read, and isn't relevant.

fgbarrios commented 9 months ago

+1 to this thread!