• Could somebody please advise?

    I’m new to WordPress but am having issues trying to do what I think should be easy.

    I have custom post types called ‘Wedding Suits’ and have added the following category and sub category:

    Wedding Hire (top level)
    – Tail Suits (child of Wedding Hire)

    I have two test posts of type ‘Wedding Suits’ and both are assigned to both categories, Wedding Hire and Tail Suits

    So I have attached the category links to the main menu no problem, if I click the ‘Wedding Hire’ category I can see the two items listed

    If I click the ‘Tailcoats’ category link I get no results, surely the posts should appear in both as they are assigned to both?

    I thought this would be the easy part of putting this site together but I have been at this for over a week.

    I have been trying to find a tutorial but not found anything yet.

    The site objective is to show products (no payment methods needed just display), and to have two levels of categories and to be able to click through the categories into the products, simple right?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You are right, it should be easy. Something is not right for sure. Are you sure the terminology is correct? Are you following the right link? You speak of Tail Suits at one point, then Tail Coats at another. Assuming it’s the tail suits term you want and have assigned it to posts, the URL should be similar to example.com/category/wedding-hire/tail-suits/

    If that checks out, some errant code could be inappropriately changing the query. Try installing and activating the health-check plugin. Invoke the troubleshooting mode and see if the same issues arise.

    If that doesn’t help, we should look at the actual SQL query to determine why nothing is returned. To see the SQL used, temporarily add the following onto the template your theme uses for category listings:

    global $wp_query;
    echo $wp_query->request;

    Be sure this is within <?php ?> delimiters. Placing it just before the loop is a good location. Most themes start the loop with something like if ( have_posts() ) :

    Thread Starter barrypoore

    (@barrypoore)

    Hi and thanks for the reply, so regardless of category I’m trying to figure out the best way to approach, so say for example just to make it easy:

    1. I have a link in the main menu that says ‘Toys’
    2. Click ‘Toys’ and it displays two categories ‘Boys’ ‘Girls’
    3. Click ‘Boys’ and it loads up items of boys toys
    4. Click ‘Girls’ and it loads up items of girls toys

    So it’s just as simple as that really, so as I’m new to WP coming from Drupal.

    a) Would the Toys page be a standard page and in that page template I use WP_Query to fetch the two categories?

    b) Or would I add the categories url to the main menu and not create a standard web page called toys?

    I would have thought ‘a’ was the right answer, create a standard web page called ‘Toys’, create a custom template for it that gets the categories, when clicking a category say ‘Boys’ it would then go to an archive template which displays the toys, then you can click through into a toy which would then lead you into the post page.

    Does the above sound about right? I’m just concerned I’m going to spend time building it but not applying the standard WP way of doing it.

    I kind of have it almost working but not convinced I’m doing it the correct way, I’m surprised I’ve not been able to find a simple tutorial on the subject.

    Thanks in advance ??

    Moderator bcworkz

    (@bcworkz)

    If you are willing to do a little custom coding on templates, you an do anything you want. But sticking with things WP does by default is more reliable and saves you time and effort. In the toys scenario you use, I would do as you’ve done with your actual categories — toys would be a top level category, boys and girls are child categories of toys. Posts of whatever type could be assigned any combination of toys, boys and/or girls.

    The toys category link in your menu would be /category/toys/. That page will list any posts assigned the toys category. Whether child categories are displayed on this page depends on your theme. You can always customize the template if your preferred theme does not already do this. Child links would be /category/toys/boys/ and /category/toys/girls/. Each resulting page displays posts assigned the respective category.

    Except maybe for the display of child categories on the parent’s page, all of this is automatic by default. There’s no need to do anything special. Just make posts and assign categories.

    You’re having trouble with the equivalent of the girls category page not displaying posts assigned that category. If you’re dealing with the standard ‘post’ post type, there shouldn’t be any trouble, but plugins can sometimes interfere with proper functioning. If your ‘girls’ category has post types other than the standard ‘post’ post type, ‘product’ perhaps (or wedding-suits), then the default WP_Query object can sometimes need some help in getting other post types besides ‘post’. The solution is fairly simple, but does require a bit of custom work. Since you are seeing custom post types in the top level categories, there shouldn’t be any need to help WP_Query with child categories.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘categories and items’ is closed to new replies.