This thread is resolved. Here is a description of the problem and solution.
Problem:
The client was experiencing an issue where posts were not displaying unless one post was translated, even though the WPML settings were set to 'Translatable - use translation if available or fallback to default language'. The posts were sorted by a custom taxonomy and needed to be visible in the Spanish translation without being translated, as they linked to primarily English content.
Solution:
We resolved the issue by adding the parameter
'hide_empty' => false
to the
get_terms()
function in the custom WP_Query. This allowed terms with no posts translated into the secondary language to be displayed.
$terms = get_terms(array( 'taxonomy' => $taxonomy_slug, 'child_of' => $parent_term_id, // Specify the parent term ID 'hide_empty' => false ));
If you're experiencing a similar issue, we recommend trying this solution. However, please note that this solution might be irrelevant if it's outdated or not applicable to your case. We highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket with us.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Tagged: Bug, Custom Work
This topic contains 16 replies, has 2 voices.
Last updated by Long Nguyen 8 months, 3 weeks ago.
Assisted by: Long Nguyen.
Author | Posts |
---|---|
February 29, 2024 at 2:39 pm | |
kurtK-7 |
Posts not showing up unless 1 is converted even though the setting is set to default |
February 29, 2024 at 3:52 pm | |
February 29, 2024 at 8:50 pm #15360628 | |
kurtK-7 |
I was asked to create a stripped down version of the site to allow your support and development team to have an area to against. I have loaded some sample data for testing. The Language switcher is in the footer. I was not able to install the WPML ACF plugin either. hidden link Please let me know what you discover. Happy to provide greater details but all of this should exist in my chat log that this ticket was created from. |
March 1, 2024 at 8:56 am #15361503 | |
Long Nguyen Supporter
Languages: English (English ) Timezone: Asia/Ho_Chi_Minh (GMT+07:00) |
Hi Kurt, Thank you for contacting WPML support, I’m happy to help you with this issue. I'm trying to understand your issue and replicate the issue on a new installation of WordPress. But somehow I see it works properly. The steps I've done: 1. Create a Resource CPT and a Resource Category taxonomy. $taxonomy_slug = 'resource-category'; $parent_term_id = 9; /* Product Resources ID in Resources Center Categories Taxonomy */ $terms = get_terms(array( 'taxonomy' => $taxonomy_slug, 'child_of' => $parent_term_id, // Specify the parent term ID 'fields' => 'slugs', // Fetch slugs only )); // Loop through each child term foreach ($terms as $term) { // Set up the query arguments $args1 = array( 'post_type' => 'resource', 'order' => 'ASC', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => $taxonomy_slug, 'field' => 'slug', 'terms' => $term, ), ), ); // Perform the query $the_query = new WP_Query($args1); // Check if there are any posts for this term if ($the_query->have_posts()) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . esc_html( get_the_title() ) . '</li>'; } echo '</ul>'; } wp_reset_postdata(); } 5. Create a page, set the page template and translate it. Here is the new sandbox site URL hidden link Note: you shouldn't translate the category, if you translate the category, there isn't a post that is associated with the translated category and it doesn't display in the frontend. Let me know if I understand your issue correctly. |
March 3, 2024 at 10:49 pm #15367341 | |
kurtK-7 |
Thank you for looking into this further. There is a CPT - Resource Center. That CPT has two Taxonomies associated to it. One of them is Resource Center Categories and the other is Resource Center Partners. Regarding the CPT Resource Center in the WPML settings for Post Types Translation, I have that set to "Translatable - use translation if available or fallback to default language" I need these posts visible in my Spanish translation but have not future plans to translate them as they link to primarily English PDF and Video links. These posts are sorted by the custom taxonomy. The terms for the 'Resource Center Categories' are displayed as titles in an accordion interface. I would like these terms to display translated in the interface. When you arrive on the page and you are viewing the Spanish translation site, these terms (accordion section titles) should be in Spanish. For this custom taxonomy - Resource Center Categories, the WPML settings for Taxonomies Translation is set to "Translatable - use translation if available or fallback to default language." This setting is correct. I am translating these terms, and the posts assigned to these terms should display regardless of translation status. The last taxonomy, Resource Center Partners, further filters the posts to group them by company. In WPML settings for Taxonomy I also have this set to "Translatable - use translation if available or fallback to default language." As these are company names I don't imagine I would translate them but I need these terms to display regardless of the language they are being viewed in. I recognize this is custom coding with few different factors involved so I stripped it down to s simple WP_Query and ForEach loop to display the posts. I get zero results in Spanish. I have tried with the taxonomies converted into spanish as well as cleared out. // Define the parent term ID or slug // Get child terms of the parent term // Loop through each child term // Instantiate a new WP_Query object for each term // Check if there are posts available for the term // Start the loop for the term // Restore original post data |
March 3, 2024 at 11:02 pm #15367345 | |
kurtK-7 |
The more I test, the more I think the issue happens in the ForEach Loop. When I just have a WP Query to retrieve the results (without the added Foreach Loop to group the results then I get results. English - With Query and ForEach - Results for both Spanish - With Query and ForEach - Results for only the second <?php // Instantiate a new WP_Query object for each term // Check if there are posts available for the term '); // Restore original post data echo '</ol>'; endif; |
March 4, 2024 at 3:19 am #15367451 | |
Long Nguyen Supporter
Languages: English (English ) Timezone: Asia/Ho_Chi_Minh (GMT+07:00) |
Hi, As I already mentioned above, if you don't translate the term, the fallback posts are displayed correctly in the frontend (I deleted the translation of the term "Product Resources", ID 232). Please check the attached screenshot. Looking forward to your reply. |
March 4, 2024 at 3:33 am #15367472 | |
kurtK-7 |
How can I translate the terms without translating the taxonomy? |
March 4, 2024 at 6:49 am #15367565 | |
Long Nguyen Supporter
Languages: English (English ) Timezone: Asia/Ho_Chi_Minh (GMT+07:00) |
I mean you shouldn't translate the term to display the fallback posts. If you translate the term, you have to translate the posts also to display posts in the Spanish language. I hope that makes sense. |
March 4, 2024 at 11:12 pm #15372314 | |
kurtK-7 |
Please explain to me how this happens. In English All my posts show regardless of translation (grab1.png) In Spanish my posts in the ForEach Loop do not display BUT they do for While If Loop (grab3.png) Also in Spanish if I translate a single post then that translated post AS WELL AS all of my non translated posts show up under my translated taxonomy term (grab2.png) Why does translating a single post trigger the ForEach loop to look at all the non translated posts and display them under the translated taxonomy term? |
March 5, 2024 at 4:23 am #15372507 | |
Long Nguyen Supporter
Languages: English (English ) Timezone: Asia/Ho_Chi_Minh (GMT+07:00) |
Hi, I cannot replicate the issue on the sandbox site that I shared above. If I translate the category, the translation page doesn't display any translation post even if a post is translated. I'm asking our 2nd tier support about this case and update you here when I have something to share. Thanks for your patience. |
March 5, 2024 at 1:59 pm #15374863 | |
kurtK-7 |
Thank you for bringing in tier 2 support. I'd like to point out 1 additional thing that may help them with their testing. Also on my site I have Manufacturing Pricing Updates. This content is sorted by a custom Taxonomy called Product Categories. When I converted those taxonomy terms to Spanish everything still works even though the posts remain untranslated. Default Translation Terms with Default Translation Posts Translated Terms with Default Translation Posts This works perfectly and the big difference between this and the Product Resources Page is that my foreach loop goes through every parent level term vs the product resources page that goes through the child terms of a parent terms called out by the ID I hope this helps as well as demonstrates that a taxonomy can be converted and still display non translated posts inside a foreach loop. |
March 6, 2024 at 2:52 am #15376881 | |
Long Nguyen Supporter
Languages: English (English ) Timezone: Asia/Ho_Chi_Minh (GMT+07:00) |
Hi, I will check both cases with parent term and child term on the sandbox site after having more information from the 2nd tier support. Thank you. |
March 11, 2024 at 1:43 pm #15395692 | |
kurtK-7 |
Checking in as well as making sure this support ticket does not close from inactivity. Please let me know what you have found. |
March 12, 2024 at 1:23 am #15397570 | |
Long Nguyen Supporter
Languages: English (English ) Timezone: Asia/Ho_Chi_Minh (GMT+07:00) |
Hi, Our 2nd tier support is still checking the issue. I will let you know once I have any information. Thanks. |