Add term slug in URL of custom post type details page

You need to update below line at where you have register a custom post type using register_post_type function. ‘rewrite’ => array(‘slug’ => ‘movies/%cat%’) To change permalink dynamically of post type you have to add below code in functions.php file : function change_link( $post_link, $id = 0 ) { $post = get_post( $id ); if( $post->post_type … Read more

Can’t delete a custom post in front end with custom role

Look at line 63 of the code https://developer.wordpress.org/reference/functions/map_meta_cap/ If you don’t provide a specific post, it is not allowed. Your code is mixing meta capabilities with primitive capabilities. (yours are all plural or primitive) “Meta” capabilities, e.g. ‘edit_post’, ‘edit_user’, etc., are capabilities used by map_meta_cap() to map to other “primitive” capabilities, e.g. ‘edit_posts’, ‘edit_others_posts’, etc. … Read more

Display a post from custom post type only if all the selected taxonomies and custom field value matches the record

You have set “roll_number” custom field in tax_query. It should be in “meta_query”. Please try the updated code: tion exam_result_filter_function(){ $args = array( ‘post_type’ => ‘exam_result’, ); if( isset( $_POST[‘school_class’] ) || !empty( $_POST[‘academic_year’]) || !empty( $_POST[‘roll_number’]) ){ $args[‘tax_query’] = array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘school_class’, ‘field’ => ‘id’, ‘terms’ => $_POST[‘school_class’], ), … Read more

CPT Taxonomy As Archive Page – Error 404

You use the same slug clubs to register your custom post type and in rewrite when you register opposition taxonomy. Change rewrite parameter in register_taxonomy() ‘rewrite’ => array( ‘slug’ => ‘clubs/opposition’, ‘with_front’ => false ), The recognizable address will be clubs/opposition/{some-term-name} and will display posts from custom category. However, the clubs/opposition address will still not … Read more

Get posts from Custom Taxonomy

Your very first block of code is the correct way to do things. Under no circumstances should an archive template be using a custom WP_Query for querying its posts. WordPress queries the correct posts for you based on the URL, and you output them with the standard WordPress Loop: while ( have_posts() ) : the_post(); … Read more

Undefined $post in wp_query

The most reliable way to get the current post being viewed is not the global $post variable. Instead you should first check is_singular(), and then use get_queried_object() to get the post object, or get_queried_object_id() to just get the ID. if ( ! is_singular() ) { return; } $post_id = get_queried_object_id(); $args = array( ‘post_type’ => … Read more