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.48k stars 1.41k forks source link

Display Multiple Post Type Query (from Elementor instructions) not working as expected #27873

Open Kathryn-gumboots opened 1 week ago

Kathryn-gumboots commented 1 week ago

Prerequisites

Description

I want to display 4 different custom post types in the loop post widget. I have followed the instructions as in the Elementor Developer docs (and tried a few other variations too). I have not been successful in making it work. It pulls in pages, not posts. I have tried: • all plugins off (except Elementor, CodeKit & ACF) • placing post widget on a different 'clean' page. • all the different settings in the post widget.
• post widget, loop widget and gallery widget options. • Elementor support, who after a lengthy process of collecting information sent me here.

The ACF key for the post types is in singular, however I have also tried in plural as they appear in the dashboard with no change in the result.

I am not a coder. I know some CSS and can follow PHP instruction and concepts - just :)

Example page with issue: https://tarasprings.com.au/multiple-posts-test/

CleanShot 2024-06-28 at 11 36 53 CleanShot 2024-06-28 at 11 41 50 CleanShot 2024-06-28 at 11 45 44

Steps to reproduce

  1. Use Post Loop Widget.
    Add Query Id: my_query_by_post_types.

  2. Add following code to (Theme) using CodeKit set to 'everywhere'

PHP code used: <?php function my_query_by_post_types( $query ) { $query->set( 'post_type', [ 'retreat', 'workshop', 'event' ] ); } add_action( 'elementor/query/{$query_id}', 'my_query_by_post_types' );

  1. Refresh cache and page.

Expected behavior

For the post widget to display posts from my multiple custom post types

Isolating the problem

Elementor System Info

== Server Environment ==
    Operating System: Linux
    Software: Apache
    MySQL version: Source distribution v8.0.36-28
    PHP Version: 7.4.33
    PHP Memory Limit: 768M
    PHP Max Input Vars: 3000
    PHP Max Post Size: 256M
    GD Installed: Yes
    ZIP Installed: Yes
    Write Permissions: All right
    Elementor Library: Connected

== WordPress Environment ==
    Version: 6.5.5
    Site URL: https://tarasprings.com.au
    Home URL: https://tarasprings.com.au
    WP Multisite: No
    Max Upload Size: 256 MB
    Memory limit: 256M
    Max Memory limit: 768M
    Permalink Structure: /%postname%/
    Language: en_AU
    Timezone: Australia/Melbourne
    Admin Email: support@flowji.com
    Debug Mode: Inactive

== Theme ==
    Name: Hello Elementor Child
    Version: 1.0.1
    Author: Elementor Team
    Child Theme: Yes
    Parent Theme Name: Hello Elementor
    Parent Theme Version: 3.1.0
    Parent Theme Author: Elementor Team

== User ==
    Role: administrator
    WP Profile lang: en-AU
    User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

== Active Plugins ==
    Advanced Custom Fields PRO
        Version: 6.3.2.1
        Author: WP Engine

    Advanced Editor Tools
        Version: 5.9.2
        Author: Automattic

    Advanced Post Queries
        Version: 1.1.3
        Author: Shabti Kaplan

    Classic Editor
        Version: 1.6.3
        Author: WordPress Contributors

    CodeKit - Custom Codes Editor PRO
        Version: 2.3.8
        Author: Bilal Tas

    Code Snippets
        Version: 3.6.5.1
        Author: Code Snippets Pro

    Dynamic Visibility for Elementor
        Version: 5.0.11
        Author: Dynamic.ooo

    Elementor
        Version: 3.22.3
        Author: Elementor.com

    Elementor Pro
        Version: 3.22.1
        Author: Elementor.com

    Essential Addons for Elementor
        Version: 5.9.24
        Author: WPDeveloper

    Essential Addons for Elementor - Pro
        Version: 5.8.16
        Author: WPDeveloper

    Google Listings and Ads
        Version: 2.7.4
        Author: WooCommerce

    Header Footer Code Manager
        Version: 1.1.38
        Author: DraftPress

    Pinterest for WooCommerce
        Version: 1.3.24
        Author: WooCommerce

    Pixel Cat Lite
        Version: 3.0.5
        Author: Fatcat Apps

    Plugin Notes Plus
        Version: 1.2.6
        Author: Jamie Bergen

    Redirection
        Version: 5.4.2
        Author: John Godley

    Security Optimizer
        Version: 1.5.0
        Author: SiteGround

    Speed Optimizer
        Version: 7.6.0
        Author: SiteGround

    UpdraftPlus - Backup/Restore
        Version: 2.24.3.0
        Author: UpdraftPlus.Com, DavidAnderson

    VBOUT Elementor Plugin
        Version: 1.0.5
        Author: VBOUT Inc.

    VBOUT Woocommerce Plugin
        Version: 3.6.4
        Author: VBOUT Inc.

    VBOUT Wordpress Plugin
        Version: 1.2.6.8
        Author: VBOUT Inc.

    WooCommerce
        Version: 9.0.2
        Author: Automattic

    WooCommerce Shipping &amp; Tax
        Version: 2.6.0
        Author: WooCommerce

    WooCommerce Stripe Gateway
        Version: 8.4.0
        Author: WooCommerce

    Woo Custom Emails Per Product
        Version: 2.2.9
        Author: Alex Mustin

    WooPayments
        Version: 7.8.1
        Author: Automattic

== Elements Usage ==

    container : 43
        blockquote : 3
        button : 68
        container : 252
        countdown : 4
        eael-adv-accordion : 2
        form : 8
        gallery : 3
        heading : 344
        icon : 30
        icon-list : 13
        image : 43
        media-carousel : 5
        portfolio : 1
        posts : 1
        price-list : 1
        testimonial : 4
        testimonial-carousel : 2
        text-editor : 12
        toggle : 6
        video : 1
    page : 6
        button : 48
        container : 187
        countdown : 4
        eael-lightbox : 3
        form : 10
        gallery : 2
        heading : 195
        icon : 10
        icon-list : 23
        image : 10
        media-carousel : 4
        testimonial : 9
        testimonial-carousel : 7
        text-editor : 13
        toggle : 12
        video : 2
    popup : 12
        button : 2
        container : 12
        form : 9
        heading : 22
        text-editor : 7
    widget : 0
        form : 1
        price-list : 1
    wp-post : 0
        button : 26
        container : 125
        countdown : 2
        eael-lightbox : 4
        form : 7
        gallery : 1
        heading : 134
        icon : 6
        icon-list : 16
        image : 7
        media-carousel : 1
        testimonial : 5
        testimonial-carousel : 4
        text-editor : 11
        toggle : 10
        video : 1
    wp-page : 9
        button : 9
        container : 61
        countdown : 1
        eael-lightbox : 1
        form : 3
        gallery : 1
        heading : 65
        icon : 6
        icon-list : 5
        image : 2
        loop-carousel : 1
        loop-grid : 7
        nested-tabs : 1
        posts : 2
        testimonial : 2
        text-editor : 8
        toggle : 4
        video : 1
    single-post : 2
        container : 4
        heading : 3
        icon-list : 1
        posts : 1
        share-buttons : 1
        theme-post-content : 2
        theme-post-featured-image : 1
        theme-post-title : 1
    single-page : 5
        button : 22
        container : 147
        divider : 4
        eael-lightbox : 4
        form : 12
        gallery : 1
        google_maps : 4
        heading : 129
        icon : 5
        icon-list : 45
        image-carousel : 4
        loop-carousel : 7
        loop-grid : 16
        nested-accordion : 4
        text-editor : 16
        theme-post-content : 1
        theme-post-title : 1
        video : 1
    loop-item : 19
        button : 7
        container : 39
        divider : 1
        heading : 46
        image : 2
        testimonial : 1
        text-editor : 4
        toggle : 10
        video : 1

== Settings ==

    cpt_support: post, page, retreat-centre
    allow_tracking: yes
    unfiltered_files_upload: 1
    font_display: swap

== Features ==
    Custom Fonts: 0
    Custom Icons: 0

== Integrations ==

    woocommerce: Active

== Elementor Experiments ==
    Improved Asset Loading: Active by default
    Improved CSS Loading: Active by default
    Inline Font Icons: Inactive by default
    Additional Custom Breakpoints: Inactive
    Flexbox Container: Active
    Grid Container: Active by default
    Upgrade Swiper Library: Active by default
    Nested Elements Performance: Inactive by default
    Optimized Control Loading: Inactive by default
    Optimized Markup: Inactive by default
    Plugin Onboarding: Active by default
    Default to New Theme Builder: Active
    Header &amp; Footer: Inactive
    Elementor Home Screen: Active by default
    Editor Top Bar: Inactive by default
    Build with AI: Inactive
    Landing Pages: Inactive
    Nested Elements: Active
    Lazy Load Background Images: Inactive by default
    Element Caching: Inactive by default
    Conversion Center: Inactive by default
    Display Conditions: Active
    Form Submissions: Active by default
    Menu: Inactive by default
    Taxonomy Filter: Active by default

== Log ==

JS: showing 20 of 38JS: 2024-06-27 10:02:44 [error X 3][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view1274&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-27 11:36:03 [error X 1][https://tarasprings.com.au/wp-admin/load-scripts.php?c=0&amp;loadchunk_0=jquery-core,jquery-migrate,jquery-ui-core&amp;ver=6.5.5:2:28760] Cannot read properties of undefined (reading &#039;value&#039;) 
JS: 2024-06-27 23:58:24 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view457&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-27 23:58:24 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view592&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-27 23:58:25 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view699&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-27 23:58:25 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view843&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-27 23:58:25 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view1106&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-27 23:58:25 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view1264&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-27 23:58:26 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view1429&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-27 23:58:26 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view1531&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-27 23:58:26 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view1637&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-28 00:13:14 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view414&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-28 00:13:14 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view549&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-28 00:13:15 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view656&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-28 00:13:15 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view800&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-28 00:13:15 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view1063&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-28 00:13:15 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view1219&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-28 00:13:15 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view1317&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-28 00:29:53 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view69720&quot;) has already been destroyed and cannot be used. 
JS: 2024-06-28 00:29:53 [error X 1][https://tarasprings.com.au/wp-content/plugins/elementor/assets/lib/backbone/backbone.marionette.min.js?ver=2.4.5.e1:24:19952] View (cid: &quot;view69772&quot;) has already been destroyed and cannot be used. 

PHP: showing 4 of 4PHP: 2024-06-27 19:54:33 [notice X 81][/home/customer/www/tarasprings.com.au/public_html/wp-content/plugins/elementor-pro/core/app/modules/site-editor/data/endpoints/templates.php::150] Undefined index: condition_type [array (
  'trace' => '
#0: /home/customer/www/tarasprings.com.au/public_html/wp-content/plugins/elementor-pro/core/app/modules/site-editor/data/endpoints/templates.php(150): Elementor\Core\Logger\Manager -> rest_error_handler()
#1: ElementorPro\Core\App\Modules\SiteEditor\Data\Endpoints\Templates -> normalize_template_json_item()
#2: /home/customer/www/tarasprings.com.au/public_html/wp-content/plugins/elementor-pro/core/app/modules/site-editor/data/endpoints/templates.php(120): class type array_map()
#3: /home/customer/www/tarasprings.com.au/public_html/wp-content/plugins/elementor-pro/core/app/modules/site-editor/data/endpoints/templates.php(59): ElementorPro\Core\App\Modules\SiteEditor\Data\Endpoints\Templates -> normalize_templates_json()
#4: /home/customer/www/tarasprings.com.au/public_html/wp-content/plugins/elementor/data/base/endpoint.php(158): ElementorPro\Core\App\Modules\SiteEditor\Data\Endpoints\Templates -> get_items()
',
)]
PHP: 2024-06-27 20:01:08 [notice X 1][/home/customer/www/tarasprings.com.au/public_html/wp-content/plugins/elementor/includes/managers/image.php::113] Trying to access array offset on value of type bool [array (
  'trace' => '
#0: Elementor\Core\Logger\Manager -> shutdown()
',
)]
PHP: 2024-06-27 21:19:42 [notice X 3][/home/customer/www/tarasprings.com.au/public_html/wp-content/plugins/elementor-pro/modules/theme-builder/classes/conditions-manager.php::179] Undefined index: editor_post_id [array (
  'trace' => '
#0: Elementor\Core\Logger\Manager -> shutdown()
',
)]
PHP: 2024-06-28 10:24:01 [notice X 2][/home/customer/www/tarasprings.com.au/public_html/wp-content/plugins/elementor-pro/modules/dynamic-tags/acf/tags/acf-text.php::33] Undefined offset: 1 [array (
  'trace' => '
#0: Elementor\Core\Logger\Manager -> shutdown()
',
)]

== Elementor - Compatibility Tag ==

    Dynamic Visibility for Elementor: Incompatible
    Elementor Pro: Incompatible
    Essential Addons for Elementor: Compatible
    Essential Addons for Elementor - Pro: Incompatible
    VBOUT Elementor Plugin: Incompatible

== Elementor Pro - Compatibility Tag ==

    Dynamic Visibility for Elementor: Incompatible
    Essential Addons for Elementor: Compatible
    Essential Addons for Elementor - Pro: Incompatible
    VBOUT Elementor Plugin: Incompatible

Agreement

Daveden2 commented 6 days ago

From what I can see in the screenshot, you didn't replace the {query_id} with your custom id that you added under the Query settings in your loop grid.

Here's an example from my blog

Kathryn-gumboots commented 5 days ago

Thank you so much @Daveden2 - I knew I might be missing something obvious.

Actually - this still didn't work. The loops post widget is not displaying anything at all, and the straight up posts is displaying an exact copy of the page it is on.

Daveden2 commented 5 days ago

Let's take it step by step. In your PHP code snippet plugin, use PHP like this:

<?php 

/**
 * Update the query to use specific post types.
 *
 * @since 1.0.0
 * @param \WP_Query $query The WordPress query instance.
 */
function my_query_by_post_types( $query ) {
    $query->set( 'post_type', [ 'retreat', 'workshop', 'event' ] );
}
add_action( 'elementor/query/q_post_types', 'my_query_by_post_types' );

Where retreat, workshop, and event are the slugs for your custom post types.

image

Then, in your posts widget or loop grid widget, add q_post_types as your query_id.

image

Very important Make sure the function name my_query_by_post_types and q_post_types are unique. You should not create multiple php functions with the same name

Kathryn-gumboots commented 5 days ago

Thank you so very much. I recreated a local host version of my site to with the bare minimum plugins and this worked perfectly.

I am so grateful for your time and patience.

Warm regards, Kathryn

On Mon, 1 Jul 2024 at 16:33, Daveden2 @.***> wrote:

Let's take it step by step. In your PHP code snippet plugin, use PHP like this:

<?php

/**

  • Update the query to use specific post types.
  • @since 1.0.0
  • @param \WP_Query $query The WordPress query instance. */ function my_query_by_post_types( $query ) { $query->set( 'post_type', [ 'retreat', 'workshop', 'event' ] ); } add_action( 'elementor/query/q_post_types', 'my_query_by_post_types' );

Where retreat, workshop, and event are the slugs for your custom post types.

image.png (view on web) https://github.com/elementor/elementor/assets/105490669/4a9f3fa8-4f28-43ed-9222-f2172b4cb561

Then, in your posts widget or loop grid widget, add q_post_types as your query_id.

image.png (view on web) https://github.com/elementor/elementor/assets/105490669/ef0e091a-2f46-436c-a048-4622a6a83cf7

— Reply to this email directly, view it on GitHub https://github.com/elementor/elementor/issues/27873#issuecomment-2199346884, or unsubscribe https://github.com/notifications/unsubscribe-auth/BJQGGMXAGZZGEJLURBINPSTZKDZ4XAVCNFSM6AAAAABKBJW54KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJZGM2DMOBYGQ . You are receiving this because you modified the open/close state.Message ID: @.***>

-- Kathryn Hall Meld Creative http://www.vtldesign.com/ Graphic Design | Web Design Illustration | Words p. 0410 719 451