简体   繁体   中英

I have a wordpress site and i want to delete last two lines from all my posts remember lines are not same any plugin or solution?

我有一个 WordPress 网站,我有近 500 个帖子想从我所有的帖子中删除最后两行记住行不一样任何插件或解决方案?

You can use WP_Query to get all the posts, use the wp_update_post() function on each one, and based on what separates the "last two lines" of each post, explode it as a delimiter.

If your post is "Hi. My name is Xhynk. I love WordPress. Usually." And you have another that's "Hi. This is a post. Just a post. Yup. Just a post. Yeah."

You can use a WP_Query to grab the posts, and modify the post content with:

$content = get_the_content();
$content = explode( '. ', $content ); //explode into array joined at every period followed by space
$lines = count( $content ); // 3 in the first, 6 in the second

$count = 0;
foreach( $content as $line ){
    $count++;
    $new_content .= $line.'. ';
    if( $count == $lines - 2) break;
}

And then use wp_update_post() to swap the content. You just need an identical way to identify the last 2 lines of each post.

If you're not familiar with WP_Query and wp_insert_post, or MySQL queries with the $wpdb object, you may not want to attempt this and just do it manually. Also, take a backup of your database before bulk modifying anything like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM