[英]How do I generate numeric titled wordpress posts?
I would like to automatically generate some sequential Wordpress posts that have numeric titles, for example "1", "2", "3"... etc.我想自动生成一些顺序为 Wordpress 的帖子,这些帖子具有数字标题,例如“1”、“2”、“3”...等。
I'm looking for an automatic system since I would like my posts to go from "1" to "999999".我正在寻找一个自动系统,因为我希望我的帖子从“1”到“999999”到 go。
No post content or meta is required, only the titles.不需要帖子内容或元数据,只需要标题。
I'm aware of wp post generate but I have no idea on how to use it so that the post titles have the requirements explained above.我知道wp post generate但我不知道如何使用它以便帖子标题具有上述要求。
I'm working on a demo project so search engine optimization is not a concern at the moment.我正在做一个演示项目,所以目前搜索引擎优化不是问题。
CLI usage is accepted.接受 CLI 用法。
You can achieve that quite simply by using a for
loop with any arbitrary range (1-99 for example - or any other range you prefer)您可以通过使用具有任意范围的for
循环(例如 1-99 - 或您喜欢的任何其他范围)来非常简单地实现这一点
for i in {1..99}; do wp post create --post_title="This is post number $i" --post_status=publish; done
This will call the wp post create
command on each iteration of the loop and append the number to the post title.这将在循环的每次迭代中调用wp post create
命令,并调用 append 帖子标题的编号。
<?php // Create post object usinf for loop for($i=1;$i<=9999;$i++){ $my_post = array(); $my_post['post_title'] = '<?php echo $i;?>'; $my_post['post_content'] = 'This is my post-<?php echo $i;?>'; $my_post['post_status'] = 'publish'; $my_post['post_author'] = 1; $my_post['post_category'] = array(0); // Insert the post into the database wp_insert_post( $my_post );" }?>
wordpress appends a numeric value automatically if there's an existing post with the same post-title.如果现有帖子具有相同的帖子标题,wordpress 会自动附加一个数值。
so if the permalinks are set to be postname
the URL will look as follow:因此,如果永久链接设置为postname
,则 URL 将如下所示:
my-post
my-post-1
my-post-2
etc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.