Query var removed after rewrite

Maybe you are not using the correct hooks nor the correct rewrite rule. You are rewriting to pagename, which is for pages. You should use name to get posts by slug. add_filter(‘query_vars’, ‘cyb_add_query_vars’); function cyb_add_query_vars( $vars) { $vars[] = “item”; return $vars; } add_action(‘init’,’cyb_add_rewrite_rules’); function cyb_add_rewrite_rules() { add_rewrite_rule( ”^shows/([^/]+)/([^/]+)/?$” , ‘index.php?post_type=shows&name=$matches[1]&item=$matches[2]’ , ‘top’ ); } … Read more

Custom query works but returns “Undefined Offset: 0”

Try like this : $args = array( ‘post_type’ => ‘car’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘your category/taxonomy name for post type car’, ‘terms’ => ‘term name/category name’, ‘field’ => ‘slug’ ) ) ); $query = new WP_Query($args); $results = $query->get_posts(); print_r($results); Yes every post has different slug, even if you have … Read more

How to call custom posts

Don’t change the main query. You can simply achieve what you want by using pre_get_posts.Fall back to the default loop in category-5.php and add the following to your functions.php function include_category_cpt( $query ) { if ( !is_admin() && $query->is_category( ‘5’ ) && $query->is_main_query() ) { $query->set( ‘post_type’, ‘eveniment’ ); $query->set( ‘post_status’, ‘publish’ ); $query->set( ‘posts_per_page’, … Read more

Cherry framework adding custom post type

At the end of your code after the last } add : add_action(‘init,’products_post_type’); Make sure you’re adding this to the file in the /wp-content/your_custom_theme/includes/theme-init.php file, and then of course update the permalink. With the CherryFramework, make sure you don’t modify any of the files in the CherryFramework folder, or you’ll lose out when an update … Read more

List custom post types in metabox

<?php $args = array( ‘public’ => true, ‘_builtin’ => false ); $output=”names”; // names or objects, note names is the default $operator=”and”; // ‘and’ or ‘or’ $post_types = get_post_types( $args, $output, $operator ); foreach ( $post_types as $post_type ) { echo ‘<p>’ . $post_type . ‘</p>’; } ?> It will list of all public custom … Read more

How to rank custom post type from score points

You can run a WP_Query to get all the posts from post_type casinos and sort them with the custom field value casino_rank_score. Then you can further process it to display ranks. $args = array( ‘post_type’ => ‘casinos’, ‘meta_key’ => ‘casino_rank_score’, ‘orderby’ => ‘meta_value_num’, ‘posts_per_page’ => 350, ‘ignore_sticky_posts’ => 1, ); $my_query = new WP_Query( $args … Read more

Custom post type table

I am not 100%, or even 83%, sure what you are asking. The project seems complex and a lot a specifics are missing from the question. However, I am fairly sure that you don’t need to duplicate the entire post table or post type set of tables. I am also not even sure if you … Read more

Custom Post type is being ignored in query

I found out that I was using pre_get_post on these pages to exclude some things on the taxonomy archive pages. add_action( ‘pre_get_posts’, ‘exclude_cpt’ ); function exclude_cpt( $query ) { if ( $query->is_tax(‘results_categories’) ) { $query->set( ‘post_type’, array(‘results’) ); } return $query; } BUT I forgot to make sure this was only happening in the main … Read more