When variable value have space between word, doesnt show any result WP_Query

It is correct behavior. And the reason for this problem is pretty simple…

When you use tag param in WP_Query, then it searches for tags with given slug (string used in URLs) – so there should be no spaces. There are 7 parameters for slug searching in WP_Query:

  • tag (string) – use tag slug.
  • tag_id (int) – use tag id.
  • tag__and (array) – use tag ids.
  • tag__in (array) – use tag ids.
  • tag__not_in (array) – use tag ids.
  • tag_slug__and (array) – use tag slugs.
  • tag_slug__in (array) – use tag slugs.

As you can see none of above takes name as value.

If you want to search for tag name, then you should use tax_query:

...
'tax_query' => array(
    array( 'taxonomy' => 'post_tag', 'field' => 'name', 'terms' => $value )
)

tech