Beee
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsCouldn’t let it go ??
When I set author_name to false, the entire query collapses because the queried object returns as false. I remember now why I immediately abandoned it after testing ??
So I think author_name needs to be set and therein lies the crux of the issue.
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsI understand (you can’t test it).
I have tried setting post author to false/empty and then querying the posts, but it didn’t seem to work.
If I have some time I might revisit this to test it, because it does intrigue me.
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsI have given up on it… it takes me too much time to achieve, so I built a different solution. I now show 3 teasers per row instead of 2 which saves a lot of space and I can now easily fit 50 on a page.
See https://new.internationaldownhillfederation.org/member/emily-pross/mentioned/
I am going to look into lazy loading on a later stage. The launch is more important ?? Over 1 year work in it… Thanks for your time @keesiemeijer
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsWell I can add them, but they’re not recognised (yet).
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsI think the authors need to be added to the query, but I can’t seem to do that…
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsQuery vars are already added, because it’s used for other things as well.
function add_vars( $vars ) { $vars[] = "continent"; $vars[] = "subpage"; $vars[] = "category"; $vars[] = "booking_id"; return $vars; } add_filter( 'query_vars', 'add_vars' );
For some more clarity I added the full files to pastebin:
author.php – https://pastebin.com/W65iML2X
pre-get-posts.php – https://pastebin.com/vvkPkEw7This is the relevant part of the rewrites (bit updated for usernames)
function idf_rewrite_profile_pages() { add_rewrite_rule( 'member/([a-zA-Z0-9_-]+)/([a-z-]+)/?$', 'index.php?author_name=$matches[1]&subpage=$matches[2]', 'top' ); add_rewrite_rule( 'member/([a-zA-Z0-9_-]+)/mentioned/page/([0-9]+)/?$', 'index.php?paged=$matches[2]&author_name=$matches[1]&subpage=mentioned', 'top' ); add_rewrite_rule( 'member/([a-zA-Z0-9_-]+)/written/page/([0-9]+)/?$', 'index.php?paged=$matches[2]&author_name=$matches[1]&subpage=written', 'top' ); } add_filter( 'init', 'idf_rewrite_profile_pages', 1, 3 );
I can already visit /page/2 if a user has written that amount of posts, which can be seen on my profile, see https://new.internationaldownhillfederation.org/member/berry-plasman/written/page/2/ but if I change written to mentioned it goes to my first mentioned page (I only have one), but in my opinion the paged doesn’t throw an error because I have written enough posts to be able to create paged pages.
So I think, if a user has not written enough posts to page an author archive page, it fails…
I am starting to think it is impossible.
Forum: Developing with WordPress
In reply to: Order by user_status, meta_value, dateI created a temporary work-around until I find something better.
I just create 2 queries now:
Query posts from vip users
Query all posts, excluding previous query
Merge these 2.Not ideal, but it does the trick (for now).
Will close this topic…
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsAll good ??
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsForum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsI notice now, the page becomes unavailable due to insufficient memory… but only on the /mentioned subpage (for Emily). Not on mine.
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no posts@bdbrown thanks for the response, but my theme is 100% custom and not available anywhere else, so there’s no child theme.
@keesiemeijer thanks for the response.
I do want to mention I use Timber instead of plain PHP. Now in reply to your question.
I have made the website available @ https://new.internationaldownhillfederation.org.
The profile I am testing with is https://new.internationaldownhillfederation.org/member/emily-pross/.
As you can see all subpages work.That is not the issue, that all works. It is when a user has NOT written any posts and I want to ‘reach’ a paged (author) page.
Emily has not written any posts so a paged author page does not exist. That is what I want to ‘fake’.You can see it at my own profile: https://new.internationaldownhillfederation.org/member/berry-plasman/written/
Those are the posts written by me and the actual posts of an author page, with pagination.The author archive slug was changed as follows:
function change_author_permalinks() { global $wp_rewrite; $wp_rewrite->author_base = 'member'; $wp_rewrite->flush_rules(); } add_action( 'init', 'change_author_permalinks' );
These are my rewrite rules:
function idf_rewrite_profile_pages() { add_rewrite_rule( 'member/([a-z-]+)/([a-z-]+)/?$', 'index.php?author_name=$matches[1]&subpage=$matches[2]', 'top' ); add_rewrite_rule( 'member/([a-z-]+)/mentioned/page/([0-9]+)/?$', 'index.php?paged=$matches[2]&author_name=$matches[1]&subpage=mentioned', 'top' ); add_rewrite_rule( 'member/([a-z-]+)/written/page/([0-9]+)/?$', 'index.php?paged=$matches[2]&author_name=$matches[1]&subpage=written', 'top' ); } add_filter( 'init', 'idf_rewrite_profile_pages', 1, 3 );
This checks if a member is ‘tagged’ in any posts
$rows = $wpdb->get_results( $wpdb->prepare( " SELECT * FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE %s AND meta_value = %s ", 'idf_tagged_riders_%_member', // meta_name: $ParentName_$RowNumber_$ChildName $user_id ) ); if ( $rows ) { $post_ids = array(); foreach ( $rows as $row ) { $post_ids[] = intval( $row->post_id ); } $ppp = 14; $pages = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $offset = ( get_query_var( 'paged' ) ) ? (( get_query_var( 'paged' ) - 1 ) * $ppp ) : false; $mentioned_args = array( 'posts_per_page' => -1, 'post__in' => $post_ids, 'orderby' => 'date', 'order' => 'DESC', ); $context[ 'mentioned' ] = get_posts( $mentioned_args ); $amount_posts = count( $context[ 'mentioned' ] ); $amount_pages = intval( round( count( $context[ 'mentioned' ] ) / $ppp ) ); if ( $amount_pages > 1 ) { $context[ 'mentioned_paging' ] = true; $big = 999999999; $args = array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '/page/%#%', 'total' => $amount_pages, 'current' => max( 1, get_query_var( 'paged' ) ), 'show_all' => false, 'end_size' => 3, 'mid_size' => 2, 'prev_next' => true, 'prev_text' => __( '« Previous' ), 'next_text' => __( 'Next »' ), 'type' => 'list', ); $context[ 'pagination' ] = sprintf( '<div class="paginator">%s</div>', paginate_links( $args ) ); } }
This is my pre get posts:
function alter_query_for_author_mentioned_subpages( $query ) { if ( ! is_admin() && $query->is_main_query() && is_author() && 'mentioned' == get_query_var( 'subpage' ) && false != get_query_var( 'paged' )) { $member_name = $query->query[ 'author_name' ]; $user_id = get_user_by( 'slug', $member_name )->ID; global $wpdb; $rows = $wpdb->get_results( $wpdb->prepare( " SELECT * FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE %s AND meta_value = %s ", 'idf_tagged_riders_%_member', // meta_name: $ParentName_$RowNumber_$ChildName $user_id ) ); if ( $rows ) { $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; // when var_dumped on /member/emily-pross/mentioned/page/2/, output shows correct page number $post_ids = array(); foreach ( $rows as $row ) { $post_ids[] = intval( $row->post_id ); } $authors = get_all_authors_ids(); $authors[] = $user_id; $query->set( 'author__in', $authors ); $query->set( 'post__in', $post_ids ); } } } add_action( 'pre_get_posts', 'alter_query_for_author_mentioned_subpages' );
Any thoughts ?
- This reply was modified 7 years, 2 months ago by Beee.
Forum: Plugins
In reply to: [Theme My Login] Filter available to add placeholders for passwords ?Jeff can you give me some intel on how to remove this action ? I can’t seem to do it.
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsI think if I can override the authors, it should be able to do, but this doesn’t work (yet) on an author page.
Forum: Fixing WordPress
In reply to: Create fake paged author pages when there are no postsI tried working with pre_get_posts to override the query (and the authors), since an author page only shows posts from author X… but no luck…
Forum: Developing with WordPress
In reply to: Output of get permalink stops db saveI have it working in twentytwelve but it won’t work in several templates I have tested it with….