-1

I want to copy/move all tags of a post into posts content, as text form not in a link form.

For example:

A post has:

  • a title in title field,
  • some content in content field (like: a boy has good nature),
  • three tags (like: x1,x2,x3).

Can we copy all tags of that post in their content field, like:

A post has:

  • a title in title field,
  • some content in content field (like: a boy has good nature x1 x2 x3),
  • three tags (like: x1,x2,x3).

as in text, not in link form.

0

You can simply preprocess the content by adding a filter to the_content like that:

function wpse_337486( $content ) {

    if ( is_single() ) {

        // Get the current post.
        global $post;

        // Get all post tags. Get only their names.
        $tags = wp_get_post_tags($post->ID, ['fields' => 'names']);

        // Append post tags to content.
        $content = $content . ' ' . implode(' ', $tags);
    }

    return $content;
}

add_filter( 'the_content', 'wpse_337486' );
  • no, actually i want: SQL Query : how copy all tags of post into their post content in wordpress by sql query – Neeraj Bill May 10 at 9:41
  • kindly, do by sql query, to changes data in the_content of post, by all tags of post, thanks – Neeraj Bill May 10 at 9:42
  • @NeerajBill – Why? Why SQL? What exactly is the root cause why you want to do it with SQL? – leymannx May 10 at 9:57
  • because want to use this in search – Neeraj Bill May 10 at 9:59
  • @NeerajBill – Sounds you should simply hook into the post save action. As you don't want to run the SQL query every month or so again to update all new posts manually. – leymannx May 10 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.