• Resolved WebTechGlobal

    (@webtechglobal)


    Hey,

    Recently something like this stopped working for me…

    $arg = array(‘child_of’ => $catid,’hide_empty’ => false);
    $subcategories = get_categories( $arg );

    This is a touch different from what I had when the bug came about but I’m struggling to populate $subcategories with any data in the returned array despite the fact that $catid is a category with children. This worked perfect in the last 2-3 months then suddenly no longer returns anything.

    It results in duplicate categories as the script then behaves as if no matching category was found later on.

    Anyone have any ideas what I’m doing wrong?

    Thanks for your help
    Ryan Bayne

Viewing 9 replies - 1 through 9 (of 9 total)
  • esmi

    (@esmi)

    Does it work if you replace $catid with the id of a specific category with children?

    Thread Starter WebTechGlobal

    (@webtechglobal)

    Wat the hell! It works with the cat id replacing the variable.

    But the variable is populated before hand so whats the issue there? I can’t believe it, I’ve tried everything today.

    We need to talk lol

    I was going to reply to you “Thats like asking if the variable is populared before hand and it is” but I thought I’d entertain you and see what happens. Glad I kept my mouth shut, been a long 16 actually thats 17 hours.

    Thanks
    Ryan

    Thread Starter WebTechGlobal

    (@webtechglobal)

    I’m going to guess you know why this is and all I can think is its something to do with arrays that I’ve just not come across.

    However just to be clear, I’m echoing $catid right before this function and it does display the id.

    The other thing that would never have had me trying that above is the fact this used to work previously, no idea when it stopped working because I don’t use the plugin all the time only customers do.

    You wouldnt be interested in CSV 2 POST now would you, with a big discount ofcourse, email [email moderated]
    Thanks
    Ryan

    esmi

    (@esmi)

    Sounds like your problem is grabbing that $catid variable higher up the script. Working with loops sometimes means that what you think it’s doing isn’t what it’s really doing. ??

    It might be worth echoing out the $catid variable as it’s set and then again just before you set up $arg so you can get a handle on what’s happening. That’s what I normally do when I get situations like this.

    Thread Starter WebTechGlobal

    (@webtechglobal)

    Looks like you wrote this about same time as my comment. $catid is defo printing, had it echoing the ID for that last 10 hours and ensuring the important values are passed.

    I’ve been on PHP for almost 2 years, WordPress for almost 1 year now. I don’t get this at all!

    Ryan

    esmi

    (@esmi)

    How are you setting $catid? Maybe you’ve used an older piece of code that’s no longer supported?

    Thread Starter WebTechGlobal

    (@webtechglobal)

    $catid = wp_insert_category when the parent category requires creation but that does not matter because it has no children yet.

    I use $catid = get_cat_ID( $categoryname1 ); for when the parent is found to already exist. So either way $catid is populared and as far as I’m aware both only populate the variable with an integer not an array or anyting.

    What do you think? Just going to read about arrays see if there is something I have missed about the value you pass to them.

    Thanks again
    Ryan

    esmi

    (@esmi)

    $catid = wp_insert_category

    That’s going to return a boolean by default which won’t work with get_categories. Have you taken account of this?

    Thread Starter WebTechGlobal

    (@webtechglobal)

    It returns the ID of the category just created otherwise it returns false ?? defo, because I use it to populate $catid.

    With all that, I now have my fix…

    $arg= array();
    $arg[‘child_of’] = $catid;
    $arg[‘hide_empty’] = false;
    $subcategories = get_categories( $arg );

    It seems to work just fine, still thanks too you for pushing me to debug in a way I never even considered. I’d love to know why the old method I was using suddenly stopped working!

    Thanks ESMI been great,email me if you ever need a csv/affiliate datafeed import plugin, the best one ever! lol

    Ryan

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘get_categories Problem – Does Not Return Children’ is closed to new replies.