• Resolved mateuszbajak

    (@mateuszbajak)


    Hi,
    Plugin is awesome ?? But works only on category.php I need order my categories on page-slug.php template too.

    How to do that? I tried this and it doesn’t work:

    $args = array(
            'posts_per_page' => -1,
            'parent'  => 0,
            'hide_empty' => false,
            'orderby' => 'meta_value',
            'order' => 'ASC',
            'meta_key' => 'tax_position'
         );
    $tax_terms = get_categories($args);

    Is there a temporary solution until update release?

    Thanks in advance,
    Regards,
    Mateusz Bajak

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hello Mateusz,

    I’m a bit confused about what you’re trying to achieve. Are you trying to return different types of taxonomies, in the order defined by the user? If so, here is my response:

    I’ve been very busy this morning so I haven’t been able to test this myself, but I believe there are two issues with the snippet you shared.

    First, you should be using the get_terms() function instead of get_categories(). get_terms() will allow you to retrieve any type of taxonomy (tags/categories/custom-defined taxonomies), while get_categories() will only return the categories.

    Second, I believe your orderby call should be set to 'tax_position'.

    Can you try this snippet:
    `
    $args = array(
    ‘taxonomy’ => ‘my_taxonomy’ // your taxonomy here, e.g. categories, tags, custom
    ‘posts_per_page’ => -1,
    ‘parent’ => 0,
    ‘hide_empty’ => false,
    ‘orderby’ => ‘tax_position’,
    ‘order’ => ‘ASC’,
    ‘meta_key’ => ‘tax_position’
    );
    $tax_terms = get_terms( $args );
    `

    Let me know if (1) that works or (2) if I misunderstood your question/objective.

    Cheers,
    Kevin.

    Thread Starter mateuszbajak

    (@mateuszbajak)

    Hi Kevin,

    Quick response ??
    I use get_categories() becouse I need to order categories (I don’t have any other taxonomies). Anyway:

    I tried set ‘orderby’ => ‘tax_position’ before I wrote this topic. Unfortunetly this doesn’t work.

    I need to get categories in order defined by user on page-slug.php <– Is that clear now? ?? I know I have not very well grammar (I’m not native English). Sorry about that.

    Thanks in advance,
    Regards,
    Mateusz Bajak

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi Mateusz,

    Your grammar is fine :-). What I’m not understanding (and I apologize if I’m being dense here) is what you mean by page-slug.php? You’re trying to retrieve the categories taxonomy defined by the user, and on which page does the user define this order? Unless I’m mistaken, for each taxonomy (e.g. categories), there is only one page where you can re-arrange them (e.g. {wordpress_site}/wp-admin/edit-tags.php?taxonomy=category).

    Let me know!
    Kevin.

    Thread Starter mateuszbajak

    (@mateuszbajak)

    Hi,

    Sorry for that I wasn’t replay. Anyway:
    By page-slug.php I meant a page template for example page-contact.php or page-gallery.php Below is a link to tutorial what is a page template and how to create one: https://www.wpbeginner.com/wp-themes/how-to-create-a-custom-page-in-wordpress/

    Best regards,
    Mateusz

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @mateuszbajak,

    I understand you now. I’m testing this right now and I’ll get back to you soon.

    Kevin.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @mateuszbajak,

    I just tested this and it worked fine for me.

    Here is what I did:
    – Using a fairly clean install (not many other plugins or data)
    – Created a new page template “page-testing.php”
    – Added the following code to my page template:

    $args = array(
            'posts_per_page' => -1,
            'parent'  => 0,
            'hide_empty' => false,
            'orderby' => 'meta_value',
            'order' => 'ASC',
            'meta_key' => 'tax_position'
         );
    $tax_terms = get_categories( $args );
    
    echo '<pre>'; var_dump( $tax_terms ); echo '</pre>';

    – Created a new post and assigned it to my “page testing” template
    – Added 5 taxonomy terms to the category taxonomy
    – Ordered them
    – Loaded my page template
    – Categories were in order I specified in the admin

    I made new terms, changed the order, etc. and each time the order was returned correctly.

    I’m not sure what I’m doing differently than you. Do you see any differences in what I did compared to what you’re doing?

    Let me know,
    Kevin.

    • This reply was modified 7 years, 11 months ago by yikesitskevin.
    Thread Starter mateuszbajak

    (@mateuszbajak)

    I checked my code again and I saw that I printed my taxonomies in wrong way (stupid me) ;_;
    Sorry for that. Anyway thanks in help ??

    Regards,
    Mateusz

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hey Mateusz,

    No problem glad it’s working ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Plugin doesn’t work on page template’ is closed to new replies.