10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.23k stars 312 forks source link

BUG: Pages get indexed as pod type when they show them via an Elementor Widget #3924

Closed gyetger closed 1 month ago

gyetger commented 1 month ago

Describe the bug

I have a Custom Post Type with the Pods plugin. Let's call it "Map". I have a page with an Elementor Widget (Portfolio) showing random Maps.

If I sync only the Maps to ElasticSearch, everything is fine. If I sync pages, too, the above said page gets indexed as one of the Map shown by the widget. The _id and the post_title is that of the page, but everything else comes from the Map, so I can't even exclude it by filtering the "post_type".

If only the Maps are synced, but I later modify the page with the Widget, it still gets indexed as a "map".

Steps to Reproduce

  1. Create a Custom Post Type with Pods.
  2. Add a few posts for this type.
  3. Create a new page with Elementor, using a Widget that displays these posts. (e.g. Portfolio)
  4. You will have n+1 posts indexed for the custom post type.

Screenshots, screen recording, code snippet

Array
(
    [0] => Elastica\Result Object
        (
            [_hit:protected] => Array
                (
                    [_index] => wpteszt
                    [_type] => _doc
                    [_id] => 413
                    [_score] => 0
                    [_source] => Array
                        (
                            [post_title] => First test
                            [thumbnail] => 
                            [post_id] => 413
                            [terms] => Array
                                (
                                )
                            [meta] => Array
                                (
                                    [some_field] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [date] => 2024-05-31
                                                    [datetime] => 2024-05-31 11:11:00
                                                    [boolean] => 
                                                    [double] => 1111
                                                    [raw] => 1111
                                                    [time] => 11:11:00
                                                    [value] => 1111
                                                    [long] => 1111
                                                )
                                        )
                                )
                            [post_type] => foo_type
                            [permalink] => https://***/foo_type/first/
                        )
                )
        )
    [1] => Elastica\Result Object
        (
            [_hit:protected] => Array
                (
                    [_index] => wpteszt
                    [_type] => _doc
                    [_id] => 414
                    [_score] => 0
                    [_source] => Array
                        (
                            [post_title] => Second test
                            [thumbnail] => 
                            [post_id] => 414
                            [terms] => Array
                                (
                                )
                            [meta] => Array
                                (
                                    [some_field] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [date] => 1970-01-01
                                                    [datetime] => 1970-01-01 00:00:01
                                                    [boolean] => 
                                                    [double] => 222
                                                    [raw] => 222
                                                    [time] => 00:00:01
                                                    [value] => 222
                                                    [long] => 222
                                                )
                                        )
                                )
                            [post_type] => foo_type
                            [permalink] => https://***/foo_type/second/
                        )
                )
        )
    [2] => Elastica\Result Object
        (
            [_hit:protected] => Array
                (
                    [_index] => wpteszt
                    [_type] => _doc
                    [_id] => 415
                    [_score] => 0
                    [_source] => Array
                        (
                            [post_title] => Elementor #415
                            [thumbnail] => 
                            [post_id] => 415
                            [terms] => Array
                                (
                                )
                            [meta] => Array
                                (
                                    [some_field] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [date] => 1970-01-01
                                                    [datetime] => 1970-01-01 00:00:01
                                                    [boolean] => 
                                                    [double] => 222
                                                    [raw] => 222
                                                    [time] => 00:00:01
                                                    [value] => 222
                                                    [long] => 222
                                                )
                                        )
                                )
                            [post_type] => foo_type
                            [permalink] => https://***/elementor-415/
                        )
                )
        )
)

Environment information

No response

WordPress and ElasticPress information

WordPress

WordPress Environment

wp_version: 6.5.2 is_multisite: false theme: Hello Elementor (3.0.1) plugins: ElasticPress (5.0.2), Elementor (3.21.2), Elementor Pro (3.21.1), Pods - Custom Content Types and Fields (3.2.1)

Server Environment

php_version: 7.4.33 memory_limit: 1000M timeout: 30

Code of Conduct

felipeelia commented 1 month ago

@gyetger can you please share your EP Status Report? Especially the part with all your plugins, theme, and post types.

gyetger commented 1 month ago

@gyetger can you please share your EP Status Report? Especially the part with all your plugins, theme, and post types.

I've done a "Delete all data and start fresh sync" with only "Pages" and "proba" pods type (and unnecessary plugins turned off). As you can see below, there are 6 pages and 2 "proba" posts in this test WordPress site. The index has 8 items, but 3(!) of those are marked as "proba" type, and one of them has the title of the page: "Elementor #415"

Failed Queries

WordPress

WordPress Environment

wp_version: 6.5.2 home_url: https://wpteszt.****.hu site_url: https://wpteszt.****.hu is_multisite: false theme: Hello Elementor (3.0.1) plugins: ElasticPress (5.0.2), Elementor (3.21.2), Elementor Pro (3.21.1), and Pods - Custom Content Types and Fields (3.2.1) revisions: 25

Server Environment

php_version: 7.4.33 memory_limit: 1000M timeout: 30

Indexable Content

WP Teszt — https://wpteszt.****.hu

post_count: 1 page_count: 6 e-landing-page_count: 0 elementor_library_count: 10 exlibris_count: 4 foto_count: 9 kotet_count: 2 muvek_count: 4 proba_count: 2 terkeptar_count: 31 post_meta_keys: 0 page_meta_keys: 0 e-landing-page_meta_keys: 0 elementor_library_meta_keys: 0 exlibris_meta_keys: 26 foto_meta_keys: 18 kotet_meta_keys: 6 muvek_meta_keys: 5 proba_meta_keys: 1 terkeptar_meta_keys: 59 total-all-post-types: 97 distinct-meta-keys: amicus_document_id, mongo_document_id, cim, egysegesitett_cim, annotation, ...

ElasticPress

Settings

host: http://localhost:9200 index_prefix: language: hu_HU per_page: 350 network_active: false

Timeouts

request_timeout: 5 index_document_timeout: 15 bulk_request_timeout: 30

Elasticsearch Indices

wpteszt****hu-post-1

health: yellow status: open index: wpteszt****hu-post-1 uuid: _ac-YxsgTKar7T41o_cc-g pri: 5 rep: 1 docs.count: 8 docs.deleted: 0 store.size: 117.4kb pri.store.size: 117.4kb total_fields_limit: 5000 analyzer_language: hungarian stop_language: hungarian snowball_language: Hungarian

Last Sync

2024/06/07 4:53:26 pm

method: WP Dashboard is_full_sync: Yes end_date_time: 2024/06/07 4:53:28 pm total_time: 0 hours, 0 minutes, 3 seconds total: 8 synced: 8 skipped: 0 failed: 0 errors: array ( ) trigger: manual final_status: success

Feature Settings

Related Posts

active: true force_inactive: false

github-actions[bot] commented 1 month ago

It has been 3 days since more information was requested from you in this issue and we have not heard back. This issue is now marked as stale and will be closed in 3 days, but if you have more information to add then please comment and the issue will stay open.

gyetger commented 1 month ago

@felipeelia I have provided the feedback you had asked for.

felipeelia commented 1 month ago

@gyetger, as it depends on some 3rd party plugins, it may be hard to debug. I'll try to give it a look and share my findings here. Most likely, the problem comes from some code setting up the $post global variable and not setting it back. That could be a good starting point for you to debug it further.

gyetger commented 1 month ago

@felipeelia Thank you. I tried a few more Elementor Widgets: Loop Grid, Posts. The result is the same, the page is indexed as the pod type. If I use the widget of the Pods plugin ("Pods - List Items"), then there is no problem.

felipeelia commented 1 month ago

@gyetger I'm able to reproduce the error using the Loop Grid widget even without using Pods. The problem is in Elementor Pro: it somehow sets the global $post variable in a way that calling wp_reset_postdata() won't set it properly again.

You can reproduce that by changing the render() method of the \ElementorPro\Modules\Posts\Skins\Skin_Base class. If you add global $post; to its beginning and output that variable after the wp_reset_postdata() call, it will still contain the post displayed inside the loop. Things will work properly if you add that global statement, then add $backup = $post; right after it and just before the return, assign it back with $post = $backup;. Of course, not a solution you will want to use, as you'd lose that change when they update the plugin again.

Unfortunately, there isn't much more we can do to help you with that problem. I recommend you open a ticket with the Elementor Pro team letting them know the problem. Hopefully, they can work around that.