【问题标题】:WordPress custom post title to be added automatically as a tagWordPress 自定义帖子标题将自动添加为标签
【发布时间】:2021-09-20 15:31:45
【问题描述】:

我有一个问题。我想在我的帖子上自动添加标签,但我不知道该怎么做。我想在标签之前添加帖子标题,但我该怎么做?

   function set_archive_tag_on_publish($post_id,$post) {
  if ($post->post_type == 'movies'
    && $post->post_status == 'publish') {
      wp_set_post_tags( $post_id, 'tag1, tag2, tag3', true );
    }
  }
add_action('save_post','set_archive_tag_on_publish');

【问题讨论】:

    标签: wordpress tags


    【解决方案1】:

    2020 年更新

    Version Description
    5.5.0 Introduced default_term argument.

    自 Wordpress version 5.5.0 发布以来,您现在可以使用非常方便的 default_term argument 在注册新的自定义分类时指定默认术语。

    $args = [
        /...
        'default_term' => [ //(string|array) Default term to be used for the taxonomy.
            'name' => 'Potato', //(string) Name of default term.
            'slug' => 'potato', //(string) Slug for default term.
            'description' => 'You can spend the night inside a potato, https://www.youtube.com/watch?v=h2mj-7-Zklw', //(string) Description for default term.
        ],
        /...
    ];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多