Wordpress Author Link 404 - php

On a search page I allow the user to click a on the authors name to view all posts by that author. Im trying to create the link to the authors page but I keep getting 404’s. However the admin user works. I have checked the user types and they are set authors (Admin is administrator).
Code Example
get_author_posts_url(get_the_author_ID());
Result
This returns "/author/tester/" which looks correct since the admin one "/author/admin/" works. However clicking the link goes to 404.
Notes
This code is executed in a Wordpress loop.
User type is Author.
Ideally I would like to use the users nickname/display name not actual.

Try :
get_author_posts_url( $author->ID )
Also since you're using it within the loop, try without any ID :
get_author_posts_url()

Related

Display user profile field in frontend for manually created users by admin using ACF plugin

I am using a plugin that creates a shortcode for displaying user profile data in the frontend. I needed to add extra data which I made possible thanks to ACF plugin. I have been able to follow how-tos and the ACF fields now display in the frontend. This is where I am losing it.
When I view the page that displays the profile e.g example.com/profile/user, my code instead checks fields for the currently logged-in user instead of the user that I am looking at.
I cannot use get_the_author_meta() because I am manually creating the users so using that checks back for the author and instead of returning the original author it returns mine (which is how it's meant to work anyways).
Example of how I am fetching data
get_user_meta( $current_user->user_login, 'specialty', true )
specialty is the name of my custom field which I have added for user.
How can I fetch the intended username of the user I just created?
Thanks.

Wordpress User Custom Field (Checkboxes) retrieve and update - from anywhere

I've created a custom field (Checkboxes) in Wordpress > Users > Profile Fields. My site is an omni site for news, so it collects news from 20 different sources via RSS, and adds them ass posts in my Wordpress site. This is how my custom field looks like:
If you're only a visitor on my front page I'll show all posts on the startpage.
If you are a logged in user; then you should be able to select and save wich of the 20 sources you want to read in your startpage on my site. This is possible to select and save today, but only from BP User Settings page:
Now, the issue with the Users Profile Settings page is:
a) I do not want to have the form in the tab "Profile > Edit". I want my form on my startpage (above the news flow, for logged on users of course) and perhaps in a widget sometime - anyhow - the most important this is freedom to place (and style) the form wherever I want.
b) The form includes fields I want to remove (Name and Description, i.e. "sources" = field name) etc.
The user on the image above has selected and saved to read news from 2 different sources on my website. The code that handles this is on the startpage in my index.php is:
$sources = xprofile_get_field_data( 'sources', $current_user_id, $multi_format = 'array' );
query_posts(array('category__and'=>array($sources)));
Question
Is there a way of retrieving this form and update in from anywhere for logged in users?
I don't want to be bound to the idea of only having the form in the Profile Settings page. I want the user to have to form above my news flow on the startpage of my site, so the users gets the feeling of "Oh, I can customize my news flow if I create an account!" - and this should be done from anywhere for logged in users.
If I am getting it correctly, you want to display the form to logged in users. Have you tried
<?php if ( is_user_logged_in() ) { ... } ?> function?
you may also wish to update user fields with
update_user_meta()

Wordpress permalink to allow title variable in

So I built a site (In the wrong way which I can see now).
Users can post ads, they are not stored as a post, I just store the information in a table in the database.
I use a page template with parameters passed in - For example www.site/ad/?id=1&cid=2
id = id from database
cid = category id from database
I then use a wordpress page, pull params from url and load all information from DB relating to the id and category id.
In the wordpress admin there is a page set - the page uses an ad detail template for all urls that are www.site/ad/?
What I want to do now is put the ad title in the url so www.site/ad/adtitle/?id=1&cid=2
The issues with this is the page will not load as the permalink now does not correspond
perma link is www.site/ad/?
so cannot use www.site/ad/adtitle/? and still load the page with template.
I guess the question is can I make so that the page will load the url with the ad title in
I try to set permalinks to allow custom structure but no luck
Apologies about title didn't know what to call this
Fixed it with pods, which will allow you to use a page referencing a part of a url
http://blog.stefanxo.com/2014/02/how-to-create-a-pods-page/
Thanks

Wordpress automatic individual user profile pages

Wordpress builds in the principle of the author page. The author page is fine and can collect information on the author with a nicename URL. It will not do this with users whom have not written posts.
I want an effective user page that I can theme, www.example.com/user/[user_nicename]. Simple I would have thought, but I cannot find anyway for the code to find the ID of the user which is needed to make this concept work. I cannot find a plugin either. Most provide a profile page for the logged in user only and not for reference of other users.
How can this be done.
There are a few plugins to automatic user pages, did you try this one : http://wordpress.org/extend/plugins/wordpress-users/
You can use mod_rewrite to change user/[user_nicename] to pass a GET variable to a php file where you can do a wordpress table search for user_nicename and get all the variables associated with the author. For this the author need not have written a post.
You could use something like this
<?php
$username = $_GET['user'];
if (isset($username))
{
$user_ids = $wpdb->get_col("SELECT * FROM $wpdb->users WHERE user_nicename = $username");
..
I have used something like this in one of my wordpress projects. Here is the example (not working now) to the user page I made. But there I used user id instead, for less load on sql query.

wordpress - manually set the author of a post in php

I'm using a wordpress theme that allows users to create posts (they don't need to be logged in). The problem is that when the posts are displayed, <?php the_author(); ?> always shows as "admin". The post-creation form has a name field that I can get at in functions.php, but how can I manually change the author of the post to the name that was entered in the form field?
Without seeing the context, I can only offer a step in the right direction. Within a plugin or functions.php in your theme, you can call on the wp_insert_post_data filter to change the data that will be inserted as your post. For instance, if you wanted every post to be attributed to author with ID 5, you could do something like:
function my_change_author( $data , $postarr )
{
$data['post_author'] = 5;
return $data;
}
add_filter('wp_insert_post_data' , 'my_change_author' , '99', 2);
I've done something like this before where I have front end forms that I capture as posts and automatically assign to a predefined author that I call Web Monkey or something like that ;) Check out this page for more: http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data. This filter is really powerful in that you can alter your data that will become your post in anyway before it hits the database.
Have you checked what the_author_meta() contains? WP has to attach a userID to each post, so chances are it's assigning user 1 to those posts regardless of what they're entering into the box. Without seeing the custom function or knowing what theme you're using to test, it'll be pretty difficult to troubleshoot.

Categories