L
L
Legal Adviser2019-05-23 15:06:49
Taxonomy
Legal Adviser, 2019-05-23 15:06:49

Can't deal with 404 when going through taxonomy?

People, I ask you to explain (chew) me ...
There is an arbitrary entry: need
A taxonomy has been created for it: help
As a result, in the admin panel, in the left panel there is:
Need => All Need
Add Need Need
Categories Need
If we fall into the Need Categories, then the address is at us like this:

http://localhost:8089/wp-admin/edit-tags.php?taxonomy=help&post_type=need

There is a file: taxonomy-help.php which says: *
Template Name: taxonomy-help.php
* Template Post Type: need 'notall' 3. Go to the address: //localhost:8089/help/all/ or //localhost:8089/help/notall/ and get a 404 error . 4. In each heading (slug 'all'/slug 'notall') entries are attached (each has its own, for the convenience of testing). 5. If we navigate through an arbitrary entry, then we have the address: Although, when creating a post, the corresponding headings are marked in the heading (terms) section (for example: slug 'notall')

http://localhost:8089/need/testovaya-zapis-1/
I re-read and tried what is here:
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters

I can't figure out why I'm not getting anything even with this example:
<?php
$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        array(
            'taxonomy' => 'help',
            'field'    => 'slug',
            'terms'    => 'all',
        ),
    ),
);
$query = new WP_Query( $args );
?>

I tried different options, but the maximum that can be done is to display the names of all created headings (terms) on the page in the form of general text with a “dead” link (i.e. links to the current page) and the number of entries after the link.
Here is the code:
<?php
$number = 0; // 0=все рубрики. Можно ограничиться кол-вом рубрик указав соответствующую цифру.
$args = array(
  'number' => $number,
  'orderby' => 'count',
  'order' => 'DESC'
);
$terms = get_terms('help', $args);
if($terms){
  echo '<ul>';
            foreach ($terms as $term){
                echo '<a href="">';
                echo "<li>{$term->name}{$term_id->ID}";
                echo '</a>';
                echo " ({$term->count})</li>";
    // рядом в скобках указываем количество записей в категории
                }
  echo '</ul>';
    }
?>

Or in the form of a link to a category, when you go to which you get a 404 error.
Here is the code:
<?php
$term_slug = 'notall'; //передавать нужно альтернативное имя (slug)
$term_link = get_term_link($term_slug, 'help');
echo '<a href="'. $term_link .'">ссылка на раздел '. $term_slug .'</a>';
?>

Questions:
1. How to make it so that when going to //localhost:8089/help/all/ a list of posts that belongs to the 'all' slug is displayed and the list of posts of the 'notall' slug is not displayed.
2. How to make it so that when going to //localhost:8089/help/all/ a list of posts is displayed that applies to the 'all' slug and all its children.
3. How to make sure that you don’t get a 404 error during the transition?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question