Code to show related posts (custom post type and custom taxonomy/category) is messing with other code

It seemed like you did not call wp_reset_postdata() which in short, restores the context of the template tags (e.g. the_title() and get_the_title()) from a secondary query loop back to the main query loop. More details at https://developer.wordpress.org/reference/functions/wp_reset_postdata/#more-information. So basically, you just need to call wp_reset_postdata() like so, and then the issue in question would disappear: … Read more

Get X posts with the same terms as the current post (custom post type and custom taxonomy)

It’s not limiting to 5 posts That’s because the posts_per_page arg should actually be in the same level as the post_type arg and not put inside the tax_query array. I.e. $args = array( ‘post_type’ => ‘oferta’, ‘posts_per_page’ => 5, // add it here ‘tax_query’ => array( array( ‘taxonomy’ => ‘categoria’, ‘posts_per_page’ => 5, // NOT … Read more

Custom post type, when type non existing post name, it query the nearest possible post name by default. How can I disabled this behavior

Out of the box, WordPress will try to be helpful and provide the next best post if it cannot find the one you specified – in your case example/t. This feature can be deactivated, however: function stop_404_guessing( $url ) { return ( is_404() ) ? false : $url; } add_filter( ‘redirect_canonical’, ‘stop_404_guessing’ );

Custom Post Type, 404 error

I solved by eliminating the following portion of code: I don’t remember why I had to code it, it apparently solved an issue, even if I don’t remember what issue. The portion is the following: add_action(‘pre_get_posts’, function ($query) { if (!is_admin() && $query->is_main_query() && empty($query->query_vars[‘suppress_filters’])) { if (is_archive()) { if (is_category()) { $query->set(‘post_type’, [‘post’, ‘docs’]); … Read more

Admin panel search doesn’t work for a specific custom post type

When I register multiple custom post types on the init hook, I don’t use multiple add_action functions. Consider this: function m_register_custom_posts() { register_bolumpost(); register_mangapost(); } add_action(‘init’,’m_register_custom_posts’); I would also add all your custom taxonomy function calls into this function since they fire on the same init hook. You have a lot of custom functions firing … Read more