[Resuelto] Taxonomy View rendered in PHP shows no results found
Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.
Problem: I would like to use PHP to loop over all the terms assigned to a post and display some formatted text using a custom field applied to the term.
Solution: Use the native WordPress method wp_get_post_terms to get all the terms associated with a specific post. Then use foreach to loop over the terms. Inside that loop, use the types_render_termmeta API to retrieve the custom field values and echo the formatted text string.
This support ticket is created hace 6 años, 3 meses. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Thats great and works well. Perhaps you can help me with one more related thing. I have a view designed to display category terms. I am using a view instead of a category as I need to be able to colour each term depending on a color-picker custom field color assigned to it. This is working well but isnt working in my PHP file. The code I have is a simple shortcode to display the view:
Sounds like a context issue where the current post is something other than the expected current post when you call do_shortcode. You can test that by throwing in some debug code:
It should echo the title of the expected current post. If not, then you can try to modify the current post context in your code, or you can modify the View's filter to be filtered by term ID, provided by a shortcode attribute. Then you can pass whatever term IDs you want in a comma-separated string. It's best practice to use the render_view API to display a View in PHP.
The types_render_termmeta shortcode needs to know which term you want to query for the custom field value. The term_id attribute can only be omitted in 2 cases - in the context of a term archive or in the context of a term View. This is neither of those contexts, so you must add term_id to the array of parameters like this:
Hmm, I don't understand how the two code snippets you provided are connected. It seems like the $module_color should be defined in the foreach loop, like this: