• Resolved enkoes

    (@enkoes)


    Hi, just want to ask how can I create sticky tags? For example, I want to make three specific tags appear always at the front order regardless of any new tags created. Currently when user create new tags while posting, the newly assigned tags will stay at the front.

    Regards.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Marcel Pol

    (@mpol)

    Hello enkoes,

    Sorry for the slow reply.

    In the admin dashboard, the term_order that is being saved starts at 0. I can imagine that a new tag could have a term_order value set as 3 or 4 or any integer that you would want.

    Can you tell me with which plugin or code you use to create those tags on the frontend? I could see if I can write some code for you that does this.

    Regards, Marcel

    Thread Starter enkoes

    (@enkoes)

    @mpol thanks for your reply.

    I’m using Ultimate Addons for Contact Form 7 (UACF7) with Frontend Post Submission addon to let users submit their posts from frontend. The limitation with this addon is that users can’t really submit new tags but can only choose from existing tags using this form-tag: [uacf7_post_taxonomy post-taxonomy-205 tax:post_tag]. As a workaround, I let users suggest the tags from frontend and admin will manually attach these tags to the relevant post. It appears to me that new tags are always given the first order to display. Is it possible to make 3 specific tags to be always displayed in the first three order regardless any subsequent new tags assigned?

    Regards.

    Plugin Author Marcel Pol

    (@mpol)

    Hi, thank you for coming back.

    I am not planning to add sticky tags. If possible I prefer changing the term_order for newly created terms, which is much simpler.

    I assume the submitted post gets edited on the editor, where new tags can be added. The next code can be used to have new tags always have a term_order of 4, so they are always below the first three terms in the order.
    The code can be added to your own plugin or to the index.php of your theme, preferably a child theme.

    // Edit post screen, set term_order higher than 0, so it's not at the top.
    function my_customtaxorder_add_term_order( $term_id = 0, $tt_id = 0, $taxonomy = '' ) {
    if ( isset($_POST['action']) && $_POST['action'] == 'editpost' ) {
    if ( $term_id == 0 ) {
    return;
    }
    $term = get_term( $term_id, $taxonomy );
    if ( ! is_object( $term ) ) {
    return;
    }
    customtaxorder_set_db_term_order( $term_id, 4, $taxonomy );
    }
    }
    add_action( 'create_term', 'my_customtaxorder_add_term_order', 99, 3 );

    Does this work for you?
    (And yes, the editor mangles all of this).

    • This reply was modified 3 months, 3 weeks ago by Marcel Pol.
    Thread Starter enkoes

    (@enkoes)

    @mpol Thanks for your help. The code does exactly what I needed!

    My three specific tags are now always floating at the top when new tags are assigned.

    Regards.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.