Last active
July 19, 2024 09:49
-
-
Save LeMiira/1c45afb15d0099dbed14afe39c8dfc3d to your computer and use it in GitHub Desktop.
Revisions
-
LeMiira revised this gist
Jul 19, 2024 . 1 changed file with 33 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,36 @@ add_action('elementor/query/readNextQueryx', function ($query) { // Retrieve the custom field 'what_to_read_next_articles' $postsID = get_post_meta(get_the_ID(), 'what_to_read_next_articles', true); // Ensure $postsID is an array and contains only valid, existing post IDs if (!is_array($postsID)) { $postsID = explode(',', $postsID); } $postsID = array_filter($postsID, 'get_post'); // Limit to 3 posts $postsID = array_slice($postsID, 0, 3); if (!empty($postsID)) { // Set the query parameters $query->set('post__in', $postsID); $query->set('posts_per_page', count($postsID)); $query->set('orderby', 'post__in'); $query->set('ignore_sticky_posts', true); $query->set('post_type', 'any'); // This will allow fetching any post type // Ensure we're only getting published posts $query->set('post_status', 'publish'); // Remove any category or tag constraints $query->set('category__in', []); $query->set('tag__in', []); } else { // If no valid post IDs, return no results $query->set('post__in', [0]); } // Remove the function if it exists to prevent double execution remove_action('elementor/query/readNextQueryx', __FUNCTION__); }, 10, 1); -
LeMiira revised this gist
Jul 17, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ $query->set( 'posts_per_page', 3 ); $query->set( 'posts__in', $postsID ); -
LeMiira created this gist
Jul 17, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ add_action('elementor/query/readNextQuery', function ($query) { // Retrieve the custom field 'what_to_read_next_articles' which contains the IDs of posts to display $postsID = get_post_meta(get_the_ID(), 'what_to_read_next_articles', true); $query->set( 'posts_per_page', 3 ); $query->set( 'post__in', $postsID ); });