• Resolved onlineatwork

    (@onlineatwork)


    Hey team,

    i couldnt find any information about this simple function. I created 6 taxanomies via CPT UI. How can i get these in a new order ? THe Backend of CPT UI does not give me any drag and drop funktion, nether a setting, to get this done. They are created 3 Years ago and it seems like they are set up, in the order of the creation date/time. I need to change the order. How can i ? ??

    Greats and cheers

    • This topic was modified 4 years, 1 month ago by onlineatwork.

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Yeah, it’s all based on the order in which they’re registered and thus saved to the option we save things to.

    I know we have https://github.com/WebDevStudios/custom-post-type-ui/issues/546 open about this, but we haven’t done anything with it thus far.

    You could make use of the import/export functionality to re-arrange the resulting option, if you’re willing to edit JSON data directly, but I can definitely understand some hesitation there too.

    Thread Starter onlineatwork

    (@onlineatwork)

    Thanks for the quick response! Could you be a bit more detailed about the import/export function, to reorder the taxonomies? OR maybe i am a bit mor detailed to ??

    We bought a code “customization” from another Plugin team, to handle taxonomy metaboxes in the frontendupload. These are set the way the taxonomies are in the cpt ui backend.

    So my idea was, to reorder the taxonomies and all is good.
    Or is there a quick way for you to find a solution in this code?

    <?php
    
    if(!defined("ABSPATH")) die();
    $taxonomies = get_object_taxonomies( 'wpdmpro' );
    $taxonomies = array_diff($taxonomies, ['wpdmcategory', 'wpdmtag']);
    foreach ($taxonomies as $taxonomy){
        $taxonomyObj = get_taxonomy($taxonomy);
        //wpdmprecho($taxonomyObj);
    ?>
    
    <div class="card wpdmap-card-filter mb-3"  id="<?= $taxonomy ?>-section" <?php if (in_array($taxonomy, $hide)) { ?>style="display: none"<?php } ?>>
        <div class="card-header">
            <?= $taxonomyObj->label; ?>
        </div>
        <div class="card-header p-2 filter-header"><input placeholder="<?php echo __( "Search...", "download-manager" ) ?>" type="search" class="form-control form-control-sm bg-white input-sm" id="<?= $taxonomy ?>_src" /></div>
        <div class="card-body tag-card">
            <ul id="wpdm-<?= $taxonomy ?>" class="wpdm-taxonomy">
                <?php
                $term_list = wp_get_post_terms($post->ID, $taxonomy, array("fields" => "all"));
                $selectedterms = array();
                foreach ($term_list as $__term) {
                    $selectedterms[] = $__term->term_id;
                }
                $terms = get_terms(['taxonomy' => $taxonomy, 'hide_empty' => false]);
                foreach($terms as $term){
                    echo "<li class='wpdm-tag'><label><input type='checkbox' name='taxonomy[{$taxonomy}][]' ".checked(in_array($term->term_id, $selectedterms), true, false)." class='wpdmtag' value='{$term->term_id}'> <span class='tagname'>{$term->name}</span></label></li>";
                }
    
                ?>
            </ul>
        </div>
        <div class="card-footer">
            <div class="input-group">
                <input type="text" class="form-control" id="new_term_<?= $taxonomy ?>" />
                <div class="input-group-append">
                    <button type="button" class="btn btn-secondary btn-create-term-wpdm" data-taxonomy="<?= $taxonomy ?>"><i class="fa fa-plus-circle"></i></button>
                </div>
            </div>
        </div>
    </div>
        <script>
            jQuery(function ($) {
                $("#<?= $taxonomy ?>_src").on("keyup", function() {
                    var value = $(this).val().toLowerCase();
                    $("#wpdm-<?= $taxonomy ?> li").filter(function() {
                        $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
                    });
                });
    
            });
        </script>
    <?php }
    ?>
    
    <script>
        jQuery(function ($){
            $('.btn-create-term-wpdm').on('click', function (e){
                e.preventDefault();
                var tax = $(this).data('taxonomy');
                WPDM.blockUI('#'+tax+'-section');
                var term = $('#new_term_'+tax).val();
                $.get(wpdm_url.ajax, { action: 'wpdm_create_term', term: term, taxonomy: tax, __nonce: '<?= wp_create_nonce(NONCE_KEY); ?>'}, function (response){
                    if(response.success === true)
                        $('#wpdm-'+tax).append(response.html);
                    else
                        WPDM.bootAlert("<?= __( 'Error', 'download-manager' ); ?>", "<?= __( 'Failed to create term', 'download-manager' ); ?>", 400);
                    WPDM.unblockUI('#'+tax+'-section');
                });
            });
        });
    </script>
    <style>
        .wpdm-taxonomy, .wpdm-taxonomy li{
            list-style: none;
            margin: 0;
            padding: 0;
            font-size: 9pt;
        }
       .wpdm-taxonomy li label{
            font-size: 9pt;
        }
    </style>
    
    
    • This reply was modified 4 years, 1 month ago by onlineatwork.
    • This reply was modified 4 years, 1 month ago by onlineatwork.
    • This reply was modified 4 years, 1 month ago by onlineatwork.
    • This reply was modified 4 years, 1 month ago by onlineatwork.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    So, take an example for one of my personal sites.

    https://gist.github.com/tw2113/4f93ba2e9983af53b5b301397206a564

    First we have bookmark_topics for my first saved taxonomy. Then we have book_status. Topics gets registered first, followed by statuses.

    If I wanted to manually force re-order things, I could change it to the following after import:

    https://gist.github.com/tw2113/5a8de24111a38add93e12d3398ccdae5

    Where book_status is now first, followed by bookmark_topics

    It would re-save the option we have saved for taxonomies, with a new order for the taxonomies, thus changing the order in which they’re registered.

    Thread Starter onlineatwork

    (@onlineatwork)

    ok nice, where to export and import the date ? And are my posts still assigned after the process is done?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    By all means, back up first, JUST IN CASE, but yes, the actual data should be unaffected as long as you’re not changing values in the JSON data. My example above is just changing the order in which they’re presently saved, changing the order in which they’re registered, by way of a standard foreach loop.

    Thread Starter onlineatwork

    (@onlineatwork)

    i defenitly will ?? Where to find the JSON Data to change the order ?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Tools menu item, Taxonomies tab at the top.

    Thread Starter onlineatwork

    (@onlineatwork)

    thanks allot, i′ll give a feedback tomorrow! If you owuld be so kind to delete my code posted here, that would be great. Have ag ood day!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I don’t have that ability, otherwise I would. At best, a forum moderator could.

    Thread Starter onlineatwork

    (@onlineatwork)

    i am very happy to say, that the import/export does work for me! Got the taxonomies in a new order after carefully editing the exported code via – tools – taxonomies – Export Taxonomies settings. Thanks allot!

    • This reply was modified 4 years, 1 month ago by onlineatwork.
    • This reply was modified 4 years, 1 month ago by onlineatwork.
    • This reply was modified 4 years, 1 month ago by onlineatwork.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Simple Question / How to order the created taxonomies ? Not the terms.’ is closed to new replies.