Hello.
Thank you, it works.
But how would I save as a value result of this whole function?
function show_me_synonyms_and_similar_words()
{
//query
global $post;
$postid = get_the_ID();
$posttags = get_the_tags();
//get synonyms
if ($posttags)
{
foreach ($posttags as $tag)
{
$slug = $tag->slug . " ";
}
$output .= $slug;
}
$args = ["post__not_in" => [$postid], "post_status" => "publish", "orderby" => "title", "order" => "ASC", "tag_slug__and" => $output, ];
$myposts = get_posts($args);
if ($posttags)
{
echo "<h2 class='sym cust_text'>Synonyma:</h2>";
echo '<ul class="syn tab">';
foreach ($myposts as $post): ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
endforeach;
wp_reset_postdata();
echo "</ul>";
}
//search similar words by keyword
$field_c = str_replace(' ', '', strtolower(get_field("search_core")));
$field_exclude = str_replace(' ', '', strtolower(get_field("search_core2")));
if ($field_c)
{
$actual_title = str_replace(' ', '', strtolower(get_the_title()));
$s = get_search_query();
$args = ["s" => $field_c, ];
// The Query
$the_query = new WP_Query($args);
if ($the_query->have_posts())
{
$post_count = $the_query->found_posts;
if (str_contains(str_replace(' ', '', strtolower($actual_title)) , $field_c) && $post_count == 1)
{
}
else
{
_e("<h2 class='sim'>Podobná slova:</h2>");
echo "<ul>";
while ($the_query->have_posts())
{
$the_query->the_post();
if (str_replace(' ', '', strtolower(get_the_title())) !== $actual_title)
{
if (strpos(str_replace(' ', '', strtolower(get_the_title())) , $field_exclude) == false)
{
?>
<li>
<a class="sim_terms" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
}
}
}
echo "</ul>";
}
}
}
}
Ok. Thank you. Based on your answer, I was able to rewrite the code of my function and now it works:)