admin管理员组文章数量:1391995
I have more than 7500 products in woocommerce with TITLES IN UPPERCASE.
I'd like to change these to "Sentence case"
What would be the best way to apply the script to all titles in the WordPress database?
I have more than 7500 products in woocommerce with TITLES IN UPPERCASE.
I'd like to change these to "Sentence case"
What would be the best way to apply the script to all titles in the WordPress database?
Share Improve this question edited Feb 12, 2017 at 10:05 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Feb 12, 2017 at 8:24 Panait Andrei AlexandruPanait Andrei Alexandru 637 bronze badges 2- This may not have been done in Database at all, check in your WordPress Editor, if the titles there are not in ALL UPPERCASE, then it was done in CSS, in which case, it can be changed very easily. – Fayaz Commented Feb 12, 2017 at 9:08
- All title where written in upper case, and there are more then 7500 products with upper case title. Anyway Inresolved the problem with the plugin friendly case – Panait Andrei Alexandru Commented Feb 12, 2017 at 9:09
1 Answer
Reset to default 2You can do that with a command in your database:
UPDATE `wp_posts` /* Adjust the prefix! */
SET `post_title` = CONCAT(
UCASE( /* First letter uppercase */
SUBSTRING(
`post_title`, 1, 1
)
),
'',
LCASE( /* The rest in lowercase */
SUBSTRING(
`post_title`, 2, LENGTH(`post_title`)
)
)
);
If your author has a habit of posting uppercase titles, you can add a filter per plugin to change titles whenever a new post is added:
add_filter( 'wp_insert_post_data', function( array $data ) {
// list of words not to change
$protected_words = [
'SQL',
'CSS',
'BBC'
];
if ( empty( $data['post_title'] ) )
return $data;
$words = explode( ' ', $data['post_title'] );
$words = array_map( function( $word ) use ( $protected_words ) {
return in_array( $word, $protected_words )
? $word
: mb_strtolower( $word, 'UTF-8' );
}, $words );
// There is no mb_ucfirst()
$words[0] = mb_convert_case( $words[0], MB_CASE_TITLE, "UTF-8");
$data['post_title'] = join( ' ', $words );
return $data;
});
本文标签: databaseUppercase to sentence case for post titles
版权声明:本文标题:database - Uppercase to sentence case for post titles 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744581593a2613954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论