WordPress.org

Support

Support » Plugins and Hacks » Toolset Types » [Resolved] Author Archive Pagination with Types Plugin

[Resolved] Author Archive Pagination with Types Plugin

  • Dear bro,

    I am using Types plugin for a Vietnamese site. The problem is post display good in:
    http://tamsao.com/blog/tvnguyen_tamsao_admin_2012_1452

    But return 404 page in page:
    http://tamsao.com/blog/tvnguyen_tamsao_admin_2012_1452/page/2

    (I set up display 20 post per page)

    I tried to modify add_action “pre_get_posts” but not effect.

    function pre_custom_query( $query ) {
    global $ptlist;
    		$found = false;
    		$post_type = array();
    		if (strpos($current_url, '/blog/'.$curauth->user_nicename) !== false) {
    			$found = true;
    			foreach ($ptlist as $pt) {
    				$post_type[] = strtolower($pt);
    			}
    		} else {
    			foreach ($ptlist as $pt) {
    				if (strpos($current_url, '/'.strtolower($pt).'/'.$curauth->user_nicename) !== false) {
    					$found = true;
    					$post_type[] = strtolower($pt);
    					break;
    				}
    			}
    		}
    
    		// found an author page
    		if ($found) {
    			$query->set( 'post_type', $post_type );
    			$posts_per_page = get_query_var('posts_per_page');
    			if ($posts_per_page == '') {
    				$posts_per_page = 20;
    			}	
    
    			//get page number
    			$pageindex = strpos($current_url, '/page/');
    			if ($pageindex !== false) {
    				$paged = (int) substr($current_url,$pageindex+strlen('/page/'));
    			} else {
    				$paged = 1;
    			}
    
    			/*$query->set( 'paged', $paged );
    			$query->set( 'page', '');
    			$query->set( 'author_name', '');
    			$query->set( 'author', $author_id );
    			$query->set( 'is_single', false );
    			$query->set( 'is_archive', true );
    			$query->set( 'is_author', true );
    			$query->set( 'is_singular', false );
    			$query->set( 'posts_per_page', $posts_per_page );*/
    			$q = &$query->query;
    			$q['paged'] = $paged;
    			$q['post_type'] = $post_type;
    			$q['page'] = '';
    			$q['author_name'] ='';
    			$q['author'] = $author_id;
    			$q['posts_per_page'] = $posts_per_page;
    		}
    }

    with $ptlist = array('Video', 'Photo', 'Audio', 'Link', 'Quote', 'Article');

    Appreciate all feedback.

    Thank you very much,
    Tien

    http://wordpress.org/extend/plugins/types/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi Tien,

    How many published posts you have. Looks like post and page queries is different.

    Please add following code at the end of the function.

    return $query;

    [ Signature moderated. ]

    Hi Bigul,

    Thank you for a fast feedback.

    As the result of the query on right sidebar, my posts are:
    24 videos
    17 photos
    3 links
    11 quotes
    6 articles

    The code after modify is:

    function pre_custom_query( $query )
    {
    	if (!$query->is_main_query()) {
    		return;
    	}
    	$queried = false;
    	if ( is_home() ) {
    		$gsort = $_GET["sort"];
    		if ($gsort!='') {
    			if ($gsort == 'comments') {
    				$query->set( 'orderby', 'comment_count');
    			} else {
    				$query->set( 'orderby', 'meta_value_num');
    				$query->set( 'meta_key', $gsort);
    
    			}
    			add_filter( 'posts_where', 'wpa85491_filter_where' );
    		}
    		global $ptlist;
    		foreach ($ptlist as $pt) {
    			$post_type[] = strtolower($pt);
    		}
    		//$post_type = array('video','photo','audio','link', 'quote', 'article');
    		$query->set( 'post_type', $post_type );
    		//$query->set( 'posts_per_page', $posts_per_page );
    		//$query->set( 'paged', $paged );
    		$queried = true;
    	} else
    
    	if ( is_archive() ) {
    		$post_type = get_query_var('post_type');
    		if ($post_type != '') {
    			$gsort = $_GET["sort"];
    			if ($gsort!='') {
    				if ($gsort == 'comments') {
    					$query->set( 'orderby', 'comment_count');
    				} else {
    					$query->set( 'orderby', 'meta_value_num');
    					$query->set( 'meta_key', $gsort);
    				}
    				add_filter( 'posts_where', 'wpa85491_filter_where' );
    			}
    
    			$query->set( 'post_type', $post_type );
    			//$query->set( 'posts_per_page', $posts_per_page );
    			//$query->set( 'paged', $paged );
    			$queried = true;
    		}
    	} 
    
    	// Author page
    	$current_url =  $_SERVER['REQUEST_URI'];
    	$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
    	$author_id = $curauth->data->ID;	
    
    	// seperate type
    	if (!$queried) {
    		global $ptlist;
    		$found = false;
    		$post_type = array();
    		if (strpos($current_url, '/blog/'.$curauth->user_nicename) !== false) {
    			$found = true;
    			foreach ($ptlist as $pt) {
    				$post_type[] = strtolower($pt);
    			}
    		} else {
    			foreach ($ptlist as $pt) {
    				if (strpos($current_url, '/'.strtolower($pt).'/'.$curauth->user_nicename) !== false) {
    					$found = true;
    					$post_type[] = strtolower($pt);
    					break;
    				}
    			}
    		}
    
    		// found an author page
    		if ($found) {
    			$query->set( 'post_type', $post_type );
    			$posts_per_page = get_query_var('posts_per_page');
    			if ($posts_per_page == '') {
    				$posts_per_page = 20;
    			}	
    
    			//get page number
    			$pageindex = strpos($current_url, '/page/');
    			if ($pageindex !== false) {
    				$paged = (int) substr($current_url,$pageindex+strlen('/page/'));
    			} else {
    				$paged = 1;
    			}
    
    			$query->set( 'paged', $paged );
    			$query->set( 'page', '');
    			$query->set( 'author_name', '');
    			$query->set( 'author', $author_id );
    /*			$query->set( 'is_single', false );
    			$query->set( 'is_archive', true );
    			$query->set( 'is_author', true );
    			$query->set( 'is_singular', false );*/
    			$query->set( 'posts_per_page', $posts_per_page );
    
    		}
    	}
    
    	return $query;
    }
    // Display only 1 post for the original blog archive
    //add_action( 'pre_get_posts', 'pre_custom_query', 1 );
    add_action( 'pre_get_posts', 'pre_custom_query');

    But still have no effect.

    Thank you,
    Tien

    Hi Tien,

    Please remove return $query from end of the function. It is not required.

    You can also remove this:

    if (!$query->is_main_query()) {
    return;
    }

    Please check where filter posts using is_category(‘blog’)

    [ Signature moderated. ]

    Hi Bigul,

    I tried remove as your advice, but still not effect. The ‘blog’ is not a category, it’s just because my permalink config is: /blog/%author%/%postname%

    Thank you,
    Tien

    Hi Tien,

    Can you please share your admin/ftp details for debugging and tracing the issue. Hope you are in a development environment.

    You can send the details to my mail -> bigul.m@wpml.org

    [ Signature moderated. ]

    Hi Bigul,

    Because I have many important project on only one host, so I can not share admin detail but I will set you as my blog Editor that you can full permission to access template code. Is it OK?

    Thank you very much,
    Tien

    Hi Tien,

    It is ok. Hope we can access Custom Post Types too.

    [ Signature moderated. ]

    Hi Bigul,

    Finished added you as Admin of Tamsao.com. Now you have full permission for all resource of this website, include Types plugin.

    Please check your email for the password.

    Thank you,
    Tien

    Hi Tien,

    I received your mail. We will debug it and update you. Please wait.

    [ Signature moderated. ]

    Hi Tien,

    Our developer is checked the issue. Sorry, it is not related to Types plug-in. So we are helpless.

    [ Signature moderated. ]

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] Author Archive Pagination with Types Plugin’ is closed to new replies.
Skip to toolbar