Milimo Emmanuel
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: wordpress-6.4.2-it_IT.zipForum: Developing with WordPress
In reply to: WP_Query sort by multiple custom fieldsSome of the code might not show well, there is an issue with the blocks on my side.
Forum: Developing with WordPress
In reply to: WP_Query sort by multiple custom fieldsTo add to his response While WordPress doesn’t have a built-in way to sort by multiple meta keys using the
orderby
parameter, this one of the ways to use:Sorting by a Single Meta Key: If one meta key takes priority, use <code class=””>meta_key and <code class=””>orderby directly:
$args = array( 'meta_key' => 'primary_meta_key', 'orderby' => 'meta_value_num', // For numerical values 'order' => 'ASC', // Or 'DESC' ); $query = new WP_Query($args);
I believe this works. Note there are other ways such as <code class=””>posts_orderby filter, the one above is one am conversant with.
- This reply was modified 10 months, 1 week ago by Milimo Emmanuel.
- This reply was modified 10 months, 1 week ago by Milimo Emmanuel.
Forum: Developing with WordPress
In reply to: WP_Query sort by multiple custom fieldsHello @basvandertogt.
I will divide the answer in two parts:
Based on the debug query:
- The
orderby
clause is indeed missing. This aligns with the issue you’ve described. - The query structure is consistent with the code you provided. It correctly filters for events and news based on the <code class=””>type and <code class=””>from meta fields.
- The
GROUP BY wp_posts.ID
clause is likely redundant. It’s usually unnecessary for standard post queries as posts are already unique by ID.
I’ve identified a few potential issues and adjustments in your code:- Incorrect
orderby
Reference:You’re using named clauses in?<code class=””>meta_query,?but you need to reference those same names in?<code class=””>orderby. Change the?<code class=””>orderby?array to:
$orderby = [ 'type_clause' => 'ASC', // Reference the named clause correctly 'date' => 'ASC', // Sort events by date within the 'event_clause' 'date' => 'DESC', // Sort news by date within the 'news_clause' ];
2. The?<code class=””>news_clause?condition?<code class=””>[‘value’ => 0, ‘compare’ => ‘>’]?is likely unnecessary as all valid dates should be greater than 0. Consider removing it for efficiency:
'news_clause' => [ 'relation' => 'AND', [ 'key' => 'type', 'value' => 'news', 'compare' => '=' ], // Remove the condition for 'from' ]
3. Potential Issue with
date
Field: If the?<code class=””>date?field stores dates as numbers (e.g.,?Unix timestamps),?use?<code class=””>meta_value_num?in?<code class=””>orderby:$orderby = [ // ... 'date' => 'meta_value_num', ];
Here is an updated code (try and see if it works):
add_action('pre_get_posts', function ($query) { if (!is_admin() and $query->is_archive('news') and $query->is_main_query()) { $meta_query = []; $meta_query[] = [ 'relation' => 'OR', 'event_clause' => [ 'relation' => 'AND', [ 'key' => 'type', 'value' => 'event', 'compare' => '=', ], [ 'key' => 'from', 'value' => date('Ymd'), 'compare' => '>', 'type' => 'DATE' ], ], 'news_clause' => [ 'relation' => 'AND', [ 'key' => 'type', 'value' => 'news', 'compare' => '=' ], // Potentially remove the 'from' condition here ] ]; $orderby = [ 'type_clause' => 'ASC', 'date' => 'ASC', // For events within 'event_clause' 'date' => 'DESC', // For news within 'news_clause' ]; $query->set('meta_query', $meta_query); $query->set('orderby', $orderby); } });
Kindly it is not a guarantee this will work, and I have worked with the code you provided. Let me know thanks!
Forum: Developing with WordPress
In reply to: Elementor ElementPack iframe – Auto Height for cross domainHello @aldenzuck. Kindly get in touch with the plugin support page here.
Forum: Fixing WordPress
In reply to: 504 Gateway Time-out The server didn’t respond in time.Most likely, and highly unlikely it is WordPress related.
The 504 (Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.
Forum: Fixing WordPress
In reply to: 504 Gateway Time-out The server didn’t respond in time.Hello @scalabria. I am able to reach your site and access your wp-admin login page. Try to access it with a different ISP.
This is resolved.
Hi. Yes, it has been. My apologies I responded late. I reverted to PHP 8.0, and it worked. Thank you.
Forum: Fixing WordPress
In reply to: Gallery error“TypeError: Cannot read properties of null (reading ‘isSynced’)” indicates that you are trying to access a property named “isSynced” of an object that is null. In simpler terms, you are trying to use something that doesn’t exist.
Plugin or Theme Conflict:
- Deactivate all plugins and switch to the default Twenty Twenty-Four theme to see if the error persists.?If it disappears,?then a plugin or theme conflict is likely the culprit.?Reactivate plugins one by one to identify the specific one causing the issue.
- Update all plugins and themes to ensure compatibility with the latest version of Gutenberg.
Custom Block Issue (sometimes):
- Check the code of your custom block and ensure you are properly initializing variables and handling null values.
- Make sure you are using the correct import statement for necessary components like?<code class=””>InnerBlocks.
Other Potential Causes:
- Data corruption: Try clearing your browser cache and cookies, or using a different browser.
- Javascript conflict: Check for any other scripts running on your page that might be interfering with Gutenberg.
Forum: Fixing WordPress
In reply to: This page doesn’t seem to exist.Try this: Go to Settings > Permalinks > update to postname and update.
Forum: Developing with WordPress
In reply to: Heading Optimisation on MobileHello @finbow, How did you build your templates? or did you import them from somewhere? If they are compatible with Elementor, then you should just edit fine with Elementor.
Forum: Fixing WordPress
In reply to: This page doesn’t seem to exist.Forum: Fixing WordPress
In reply to: Gallery errorHello @chatty-gardener. which editor are you using? Gutenberg?
You can mark this as resolved. thank you