WordPress.org

Forums

Custom WordPress author names (7 posts)

  1. wilkyboy2
    Member
    Posted 1 year ago #

    Hi All,

    I am migrating my school's Online Newspaper from Joomla to WordPress, and I am trying to modify the theme (Twenty Fourteen), so that it uses a metadata key value as the display name for a post (since most of the content creators have had their posts submitted to the old site using an editor as a proxy, so their names are stored as 'author aliases').
    It should be as simple as:

    if (author_id = 0) {
        $author_name = $meta['alias'];
    }

    My awesome php simplification
    But where should this be implemented within the vast expanse of wordpress code.

    I would also greatly appreciate being shown how to configure all of the other author related perks (list author posts, these authors have contributed etc.)

    I would show you the site in situ, but unfortunately it is running on my local dev machine. Not that seeing it would help at all.

    any help at all would be greatly appreciated!

    -- Wilky

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    I am trying to modify the theme (Twenty Fourteen)

    Do not edit the Twenty Fourteen theme. It is the current default WordPress theme and having access to an original, unedited, copy of the theme is vital in many situations. First create a child theme for your changes.

  3. wilkyboy2
    Member
    Posted 1 year ago #

    Right now, I am more concerned about getting the site going.

    Whilst I will use a child theme, I am more concerned about my problem.

    - Wilky

  4. bcworkz
    Member
    Posted 1 year ago #

    I think you are better off doing a one time DB upgrade that updates the official post author for all posts with author aliases. Then there is no need to chase after every place author data appears and substitute the alias.

    No themes or child themes are involved. Either create a single use plugin for the task or do it from within phpMyAdmin.

  5. Ryan Kanner
    Member
    Posted 1 year ago #

    I see what you are trying to do. I would use the wp_insert_post_data function to do this. (note this is just an untested proof of concept, will probably need some tweaking.)

    function change_author( $data , $postarr )
    {
        $post_id = $postarr['ID'];
    
        $author_name = get_post_meta( $post_id, 'alias', true);
    
        if ( $data['post_author'] == 0 ){
            $data['post_author'] = $author_name;
        }
        return $data;
    }
    
    add_filter('wp_insert_post_data' , 'change_author' , '99', 2);
  6. DYC - The Voice Of Generation
    Member
    Posted 1 year ago #

    I suggest you to create a child theme and apply code to that in admin section.

    if (author_id = 0) {
    $author_name = $meta['alias'];
    }

    or you can update the current database's user table to specify your requirements.

  7. wilkyboy2
    Member
    Posted 1 year ago #

    I wrote a plugin to solve the problem and it did not require creating a child theme.

    I cleaned up the code, and will submit it to the plugin directory either tonight or tomorrow.

    I will post it here when it is uploaded. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic