• Resolved alx359

    (@alx359)


    I’m struggling with getting an MLA gallery using custom wp_query code properly sorted. Figured I need to sort images out using two categories; one’s visible (e.g. prints), and the other’s hidden and just aids defining their priority (e.g. top). That way chosen images would get displayed first on top of the others. For example:

    $tax_query =
     "array(
        'relation'              => 'OR',
        array(
            'taxonomy'          => 'attachment_category',
            'field'             => 'slug',
            'terms'             => array( 'prints','top' ),
            'orderby'           => 'terms'
            'operator'          => 'IN',
            'include_children'  => true
            ))'";

    I need the proper wp_query syntax to show all the top category images first, and the prints category images second (while excluding anything else).

    Would you please hint what I need to fix in the snippet above?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for your questions and for including the complete text of your tax_query parameter; very helpful. You are running up against some limitations of the WP_Query class and its tax_query parameter.

    The WP_Query Class orderby parameter accepts any of a specific list of values on which to sort. These do not include any ability to sort by term values assigned to the selected items.

    The WP_Query tax_query parameter does not include orderby nor order parameters of its own.

    The [mla_gallery] shortcode faithfully follows the capabilities of the WordPress core features for WP_Query, so I regret that there is no solution or your needs using the available features.

    One of the MLA example plugins, “MLA tax query Example”, demonstrates how to replace the WP_Query functions with a custom SQL query. The example was developed to increase performance but might be adapted to solve your problem. I have not looked at the code for some time and do not know how hard it would be to add something along these lines.

    You are encouraged to study and modify the example in a way that suits your needs. If you come up with a solution it would be great to see it and share it with other MLA users. If you need more specific guidance I may be able to help but it will be at least two weeks before I can find some time to do any work of my own. Thanks for your understanding and your patience.

    Thread Starter alx359

    (@alx359)

    Thanks for the insightful explanation, David. It helped me recall that the proper ‘WP way’ to sort stuff is by the menu_order column in wp_post. Initial tests show such sorting seems already built-in, so no need for any extra orderby or sql filters. What I had to do though was to set all menu_order rows first for all the media other than their default zeros.

    What I’m still missing is a ‘bulk’ action of editing menu_order from within MLA, as it isn’t exposed for multiple rows, unfortunately. Would you please advise how to do that?

    Thread Starter alx359

    (@alx359)

    Have found an excellent tool that does the bulk menu_order changes and much more: WordPress Advanced Bulk Edit by georgeiron. It isn’t free, but quite affordable for what it does (bulk editing for most post_types).

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your updates with the good news about finding a solution that works for your application.

    It’s true that the MLA Bulk Edit area does not allow for updating the menu_order field because I couldn’t think of a use case for it. Some time after that I added the [+index+] substitution parameter for bulk edit that would make some sense. Perhaps I will revisit my decision in a future MLA version.

    In the interim I am marking this topic resolved because your problem has been solved, albeit by another plugin. Please update the topic if you have any problems or further questions regarding your menu_order solution.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘wp_query sorted gallery’ is closed to new replies.