What are the ways to implement the opening of the post without the use of a redirect? The idea is as follows: Category -> Subcategory (if there is only one post in subcategory - open this post when clicked) -> Post.
Here is my code that works with JS and redirects to the desired page as it was intended.
<?php } }elseif (count($posts) == 1) { $i=1; foreach($posts as $cpost) { $number = $pr_id = sprintf("%02d", $i); $sub_newlink = get_permalink($cpost->ID); echo "<script type=\"text/javascript\">document.location.href = '".$sub_newlink."';</script>"; exit; } ?> How can this be done only with PHP and without redirection? What would the first subcategory inherit from the link of this post? Now the link of the 2 sub categories looks like this. How can it be screwed to the 1st?
<a href="<?php echo get_permalink($cpost->ID) ?>" class="wk_link" title="<?php echo($cpost->post_title); ?>"> Now my code works, but it happens as follows: 1. The subcategory has a link to the subcategory trail and only then redirect to the post from this subcategory.
Implementation 2:
elseif (count($posts) == 1) { $i=1; print_r($posts[0]->ID);