• My site has a few custom post types of its own, with associated taxonomies. One such is named ‘sessions’. When I visit the taxonomy page for one term, the relevant bit of WP’s query SQL looks like this:

    AND ((wpmm_posts.post_type = 'sessions' AND (wpmm_posts.post_status = 'publish' OR … etc

    Now I activate the Namaste plugin, and nothing appears on the page. The same section of the WP query SQL now looks like this:

    AND ((wpmm_posts.post_type = 'post' AND (wpmm_posts.post_status = 'publish' OR … etc

    Namaste has overwritten my custom post type name with ‘post’, and it has added several of its own post types. Consequently, the query returns no results.

    I can see a function ‘query_post_type’ in several Namaste PHP files, all of which manipulate the query, and my own post type goes missing.

    This is using version 2.5.9 of the plugin, on WP 6.1.1.

    I obviously won’t be able to use Namaste if it stays like this. Is there a solution?

    • This topic was modified 1 year, 11 months ago by Martin Taylor.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Bob

    (@prasunsen)

    Namaste doesn’t change the post type, it only adds. In case $query->query_vars[‘post_type’] is empty, it adds “post” plus its own.

    Your custom taxonomy needs to do the same and it will be fine. If it’s not in $query->query_vars[‘post_type’] , add it.

    Thread Starter Martin Taylor

    (@docdunning)

    Thanks for your reply, @prasunsen . Sorry, but I still maintain that there is a problem being caused by Namaste. I’ve now had the chance to trace the code.

    The URL for a WP taxonomy query is something like mysite.com/taxonomy-name/taxonomy-term. This should list all the items tagged in “taxonomy-name” with the term “taxonomy-term”, and we should see all the post types registered to the taxonomy.

    So WP does not initially populate $query->query_vars[‘post_type’] for a taxonomy page. Instead, the post type is populated later in WP_Query’s function get_posts(), in the section with this comment:

    // Do a fully inclusive search for currently registered post types of queried taxonomies.

    The problem caused by Namaste is that the pre_get_posts filter is called, and at that point, $query->query_vars[‘post_type’] is legitimately blank, so Namaste puts in the value ‘post’ and its own post types. When we return to the get_posts() function, because there is now a non-blank post type, the taxonomies are not used to add the post types we need to see.

    Namaste is setting the post types too soon. Rather than pre_get_posts, it might be better to use posts_where or posts_clauses so that WP has a chance to populate the post types for the taxonomy. Maybe, if we’re on a taxonomy page (is_tax()), Namaste shouldn’t attempt to add its own post types at all.

    As I mentioned before, this issue is preventing us from using Namaste.

    Plugin Author Bob

    (@prasunsen)

    Thanks for your feedback. We will review it when time permits. Since it may take weeks to get there, I recommend you to choose a different lms plugin.

    Thread Starter Martin Taylor

    (@docdunning)

    @prasunsen

    Thanks for that. Meantime I’ve realised that there are one or two workarounds, but neither is ideal.

    • uncheck the Namaste options “Show courses/lessons as blog posts in home and archive pages”.
    • Force a post type array into the query in my own pre_get_posts code, so that Namaste would add to it.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Namaste conflict with custom post types’ is closed to new replies.