• i am trying to add 2 default custom fields that are pre-populated. One with the authors first and last name and the other with the authors username. That way I could use this plugin to search posts by author (either username or real name). A lot of people have been trying to figure out how to search by author and although this way is kind of sloppy, i think it will work great. Let me know what you think. I left a post on Kaf’s plugin page too so if hes responds I will let you know.

    ps. I have searched and searched to no avail

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter thedesigncoalition

    (@thedesigncoalition)

    Here it is. Thanks Lester.

    Thank you Lester! (the answer to my previous post)

    <?php
    /*
    Plugin Name: WP-Add Author Custom Fields
    Plugin URI: https://www.lesterchan.net/portfolio/programming.php
    Description: Adds default author fields to make author name and username meta-data that can be searched with Kaf's search custom fields plugin (https://guff.szub.net/2006/04/21/search-custom-fields/).
    Version: 1.11
    Author: Lester 'GaMerZ' Chan
    Author URI: https://www.lesterchan.net
    */
    
    /*
    	Copyright 2007  Lester Chan  (email : [email protected])
    
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    
    ### Function: Add Author Custom Fields
    add_action('publish_post', 'add_author_fields');
    function add_author_fields($post_ID) {
    global $wpdb;
    $user_id = $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_ID");
    $first_name = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'first_name' AND user_id = $user_id");
    $last_name = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'last_name' AND user_id = $user_id");
    $user_name = $wpdb->get_var("SELECT user_login FROM $wpdb->users WHERE ID = $user_id");
    add_post_meta($post_ID, 'author_realname', $first_name.' '.$last_name, true);
    add_post_meta($post_ID, 'author_username', $user_name, true);
    }
    
    ?>

    That’s neat. So once you got everything hooked up, it works for what you want? (Ability to search by-author, I guess… So can you search for all references to “WordPress” by Author Username “thedesigncoalition”?)

    Thread Starter thedesigncoalition

    (@thedesigncoalition)

    No this is just for searching for posts by a certain person, NOT a keyword + the author. In my usage I am using Kaf’s plugin that i mentioned above and I have 3 radio buttons, so you can search by “author’s real name”, “author’s username”, or the default search “post content”.

    I believe this plugin provides the functionality you speak of.

    But…. but….. default WordPress already provides an “author archive” page for every author, so there’s already a built-in way to show all the posts by 1 author, isn’t there?

    On my site the URL works automagically, no plugin, no search required
    mysite.com/blog/author/author-username-here/

    Thread Starter thedesigncoalition

    (@thedesigncoalition)

    true true. but what if you are using wordpress as a cms for a social networking site and your end users want to look for their friend “Travis Dahl” or just search for “Travis” or just “Dahl” and they don’t know what his username is. Believe me, I am taking adavantage of that built url feature too.

    On a nother note, do you know how to change the text in that URL? for example:

    mysite.com/blog/artist/author-username-here/

    The thread

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Default Custom Fields’ is closed to new replies.