Turn all titles in wordpress powered site into “Capitalized” case

So what i need is a query or some tip on how to turn all titles on a wordpress powered website into capitalized case.

What i have now is something like this:

Read More

AAAAA BBBBB CCCCC

I want it to be like this:

Aaaaa Bbbbb Ccccc

I did try googling and searching here, but have failed at that task so any help is much appreciated!

UPDATE:

I need to update titles inside the database. Just to be clear. 🙂

Related posts

Leave a Reply

5 comments

  1. There is no function in MySQL for this, but you can create one like this:

    DROP FUNCTION IF EXISTS proper;
    SET GLOBAL  log_bin_trust_function_creators=TRUE;
    DELIMITER |
    CREATE FUNCTION proper( str VARCHAR(128) )
    RETURNS VARCHAR(128)
    BEGIN
      DECLARE c CHAR(1);
      DECLARE s VARCHAR(128);
      DECLARE i INT DEFAULT 1;
      DECLARE BOOL INT DEFAULT 1;
      DECLARE punct CHAR(17) DEFAULT ' ()[]{},.-_!@;:?/';
      SET s = LCASE( str );
      WHILE i < LENGTH( str ) DO 
        BEGIN
          SET c = SUBSTRING( s, i, 1 );
          IF LOCATE( c, punct ) > 0 THEN
            SET BOOL = 1;
          ELSEIF BOOL=1 THEN 
            BEGIN
              IF c >= 'a' AND c <= 'z' THEN 
                BEGIN
                  SET s = CONCAT(LEFT(s,i-1),UCASE(c),SUBSTRING(s,i+1));
                  SET BOOL = 0;
                END;
              ELSEIF c >= '0' AND c <= '9' THEN
                SET BOOL = 0;
              END IF;
            END;
          END IF;
          SET i = i+1;
        END;
      END WHILE;
      RETURN s;
    END;
    |
    DELIMITER ;
    

    From here.

    The you can update easily by running:

    Update wp_posts
    Set post_title = proper(post_title)
    
  2. Just use ucwords( $title ) on their own – but check your use cases very carefully – acronyms do not end up displaying as your users might expect.

    “beginners guide to TLAs” will become “Beginners Guide To Tlas”

  3. could you try wrapping wordpresses the_title(); function with ucwords and strtolower

    <?php echo ucwords(strtolower(the_title(null, null, false))); ?>
    

    From what i can gather this takes the title value uses strtolower to turn it into lowercase, then ucwords to capitalize each word.

    I haven’t tried this myself so i don’t know it it works but this is how i would try it.

    Hope this helps

    EDIT: right i’ve had a look at one of my old files, in your functions.php you could define a function to hook into the save_post action. Using the post variable you should be able to adjust that data, but like others have said you have to be careful incase it doesnt produce the desired effect.

    add_action('save_post', 'save_postdata');
    function save_postdata($post_id) {
        //edit code here
        update_post_meta($post_id, 'title', $title);
    }
    

    I’m using the update_post_meta() function, i’m not entirely sure if this has the ability to edit the title, i don’t have to ability to run a test unfortunately.

    What do you guys think?

  4. For the record, the MySQL function quoted above fails when the last character stands alone, e.g.,

    Public John q
    

    There’s an easy workaround, if you don’t need padding:

    trim(proper(concat(myfield, '    ')))