• Resolved dreamingbear

    (@dreamingbear)


    First of all thanks for the great plugin, a well-thought piece of software.
    I installed MLA and added another small plugin I wrote to add another taxonomy to attachments, so that I ended up with:
    – attachment_category
    – attachment_tag
    – autore (italian for author) with this setup

    $labels = array(
                'name' =>           'Autori',
                'singular_name' =>  'Autore',
                'search_items' =>   'Cerca autori',
                'all_items' =>      'Tutti gli autori',
                'edit_item' =>      'Modifica autore',
                'update_item' =>    'Aggiorna autore',
                'add_new_item' =>   'Aggiungi nuovo autore',
                'new_item_name' =>  'Nuovo autore',
                'menu_name' =>      'Autore',
                'popular_items'=>   'Autori apprezzati',
                'parent_item' =>    null,
                'parent_item_colon' =>      null);
            $args = array(
                'labels' =>         $labels,
                'hierarchical' =>   false,
                'public' =>         true,
                'show_ui' =>        true,
                'show_admin_column' =>      true,
                'update_count_callback' =>  '_update_generic_term_count');
    
            register_taxonomy('autore', 'attachment', $args);

    Then created two tag clouds widgets with the appropriate taxonomy, that were populated with links in the form
    mysite.com/blog/attachment_tag/tagname
    mysite.com/blog/autore/authorname

    Clicking on them got nothing (404 page) until I hooked the query with

    global $wp_query;
        if (is_tax('autore') OR is_tax('attachment_category') OR is_tax('attachment_tag')) {
            $wp_query->query_vars['post_type'] =  array( 'attachment' );
            $wp_query->query_vars['post_status'] =  array( null );
            return $wp_query;
        }
    }

    after this I got archive.php displaying nicely my taxonomy, but NOT MLA-generated taxonomies, e.g. I still get archive.php, but it’s empty.

    Questions (be patient, i’m new to this taxonomy stuff):
    1) any idea of why this strange behaviour?
    2) is this the “right way to do it” e.g. hooking the query and using archive.php (or maybe taxonomy-<taxonomy>.php?) or I could have a shortcode-powered page as a landing page for taxonomy links from the tag clouds or elsewhere?
    3) Some suggestions on how to implement a search function that searchs only attachments based on the three taxonomies terms (maybe also attachment name?) and displays them in a search result page?
    4) as a general rule, I do NOT want images to be included in results. One obvious strategy is to not attach taxonomy terms to any image I don’t want included. Nothing more refined?

    Thanks you for your attention. Really, thanks. The site I’m running is also a nonprofit, and I know the value of your time.

    https://www.ads-software.com/plugins/media-library-assistant/

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

    (@dglingren)

    Thanks for the positive feedback; I am glad you find MLA useful. Thanks as well for taking the time to explain your application and include the source code for your taxonomy and archive page modifications; that is very helpful.

    Taxonomy features in WordPress can be complicated and extending taxonomy support to attachments is not part of WordPress Core, as you’ve seen. Regarding your questions:

    1) any idea of why this strange behaviour?” You might find this earlier support topic helpful:

    Pagination Revisited

    Briefly, WordPress archive pages are designed for posts and pages; they do not work for attachments. Your hook to modify the query’s post_type and post_status is on the right track. You might try changing the post_status argument from null to ‘inherit’; that may be why the MLA-generated taxonomies do not show up. You should also consider isolating your changes in taxonomy-specific pages such as taxonomy-autore.php, taxonomy-attachment_category.php and taxonomy-attachment_tag.php.

    2) is this the “right way to do it” … ?” Yes, this is one of the “right ways to do it.” The Pagination Revisited support topic shows you how to use PHP template files to get the right results, and how to display them with a [mla_gallery] shortcodes for a paginated gallery of results as an alternative to the default WordPress archive list of Media Pages.

    You can also try a shortcode-powered page that doesn’t require PHP templates. Here’s a support topic that goes into that alternative:

    Using tag cloud shortcode to display galleries

    3) Some suggestions on how to implement a search function … ?” Here’s a simple example of a WordPress page that displays a gallery filtered by a search of the Title and Description fields:

    <h3>The Search Form</h3>
    <form id="mla-search-form" action="/search-form/" method="post">
    <input id="mla-search-box" name="search-string" type="text" value="" />
    <input id="submit" name="submit" type="submit" value="GO" />
    </form>
    
    <h3>The Search String Gallery</h3>
    
    [mla_gallery post_mime_type=all post_parent=all s="{+template:({+request:search-string+}|a-bad-term)+}" mla_nolink_text="Nothing to show." mla_debug=false]

    You can enter this on the “Text” tab of a page/post (not the “Visual” tab). Searching on taxonomy terms or a combination of terms and other field values would require a custom SQL query. You can do this with the “MLA Gallery Filters (Hooks)” described in the Settings/Media Library Assistant Documentation tab. There are examples of this approach in the /media-library-assistant/examples directory, such as mla-tax-query-example.php.txt and mla-child-term-hooks-example.php.txt. For the taxonomy terms portion of the search you might consider the WordPress get_terms() function with the name__like parameter. If you would like to pursue that approach I can give you more specific guidance. I’ve thought about adding a “Terms Search” parameter to the [mla_gallery] shortcode and I could look into that as well.

    4) as a general rule, I do NOT want images to be included in results.” I am not sure which “results” you mean; the standard “archive.php” results, perhaps? Using the taxonomy-specific templates might help, or a separate shortcode-powered page/pages. If you give me more details I can be more helpful.

    I hope that gets you started with some of the answers you need. I will leave this topic unresolved until I hear from you with a progress report or additional information/questions. Thanks for your interest in the plugin./

    Plugin Author David Lingren

    (@dglingren)

    I hope the suggestions I gave you were of help with your application.

    Since I have not heard back from you I assume you found a solution to the taxonomy and search questions you raised.

    I am marking this topic resolved, but please update it if you are still having problems or questions I can help with. Thanks for your interest in the plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘MLA taxonomy and custom taxonomy archive pages’ is closed to new replies.