WordPress.org

Ready to get started?Download WordPress

Forums

related custom type w/paging in single template (1 post)

  1. nikasama83
    Member
    Posted 3 years ago #

    Hi,

    Im having a problem which i cant seem to find solution for, i have searched the forums and this time im still clueless

    I need to make a listing of related custom types (named videos) in my single-videos.php, this problem only happens in single-videos.php. taxonomy-categoriesvideos.php works perfectly with query_posts(), i also used new WP_Query() in some other pages of my website and it works with paging.

    Please understand that getting the term for the taxonomy, and making it work in the query are NOT the problem.

    Also my level of php is medium-low =/

    If in single-videos.php i use new WP_Query(); paging wont work, /page/2/ gives error 404.

    If in single-videos.php i use query_posts() it will only show the current post, i cant seem to make it add the rest of the ids i successfully stored in a var.

    ** This is my code when new WP_query, it gives me the correct custom types inside my taxonomy. BUT paging doesnt work.

    $paged = get_query_var('paged')? get_query_var('paged') : 1 ;
    
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    $wp_query->query(array(
    	'post_type'      => 'videos',
    	'posts_per_page' => '4',
    	'paged'          => $paged,
    	'categoriesvideos' => $term->name,  
    
    ));

    **** I also tried query_posts(), problem is it keep showing me the current video custom type.

    query_posts($query_string.'&posts_per_page=4&paged='.$paged.'&post_type=videos&post_status=publish&categoriesvideos='.$term->name );

    Hopefully someone will be able to help me on this.

    - Which approach is better for single-videos.php? new WP_query() or query_posts?

    - How can i add the more ids into the query_posts($query_string.'')? I already have these ids and slugs stored in a vars from running a different query. I tried "p=" "name=" "videos=". I cant figure this one out.

    It really puzzles me this only happens in single-videos.php. In pages, taxonomy, archive, etc paging works.

    In case you wonder this is how i set my custom type

    register_post_type( 'videos' , array(
    			'labels'			=> array(
    									'name' 				=> __('Videos'),
    									'singular_name' 	=> __('Video'),
    									'description'		=> __('Videos'),
    									'add_new'            => __('Add Video'),
    									'add_new_item'       => __('Add New Video'),
    									'edit_item'          => __('Edit Video'),
    									'new_item'           => __('New Video'),
    									'view_item'          => __('View Video'),
    								),
    			'public' 			=> true,
    			'show_ui' 			=> true,
    			'capability_type' 	=> 'page',
    			'hierarchical'  	=> true, // if TRUE custom columns for admin wont show
    			'_builtin' 			=> false, // It's a custom post type, not built in!
    			'rewrite' 			=> array('slug' => 'video' ), // Permalinks format
    			'query_var'			=> 'videos',
    			'supports' 			=> array('title' , 'thumbnail' , 'page-attributes'     ),
    			'menu_icon' 		=> get_stylesheet_directory_uri() . '/videos/icon.gif', // 16px16
    
    	));

    thanks in advance

Topic Closed

This topic has been closed to new replies.

About this Topic