Sort order of blog topics by order added to post

Hello!

I’m not sure if this is possible, but that’s why I’m checking here. I’ve seen a number of posts on sorting blog topics alphabetically, but I’d like to output blog topics on the order added to the post.

Example, if I add Security, Intelligence, Mapping, I want them to appear in that order. However, by default, they seem to appear in .. I don’t know, the order the tags were created maybe? I can alphabetize them like here but that’s not really what I’m looking for. I’m just using the default loop for the time being.

{% if content.topic_list %}
{% for topic in content.topic_list %}
{{ topic.name }}{#% if not loop.last %},{% endif %#}
{% endfor %}
{% endif %}

Thank you for your post @redbranchmedia !

Hi @Oezcan , would you mind sharing your thought here?

Hey @natsumimori, and hi @redbranchmedia ,
it makes me very proud and glad that my thoughts are asked.
Thanks very much :).

I have to admit that I haven’t come into contact with it yet.
But I do my best and I came across it in my research and I think that would be the solution.

I hope that I could help with that.
Best regards
Özcan

Thank you! I will test that out and see if that does the trick.

Thanks again for your help. Unfortunately, that doesn’t look like it’ll work for what I need. That function allows me to return a specific tag or array of tags from a blog. I want to return the blog tags from the post itself in the order in which they’re added in the back-end. Do you know what the default behavior is? I can’t seem to find info on that either. It seems to maybe be based on when the tags were initially created in the blog itself?

Hello @redbranchmedia ,
Unfortunately, I don’t know the default behavior. But Google a little and found something like this:

https://community.hubspot.com/t5/Releases-and-Updates/Now-Live-Knowledge-Base-Re-order-Categories-and-Articles-Service/ba-p/418019

and this:

function change_posts_order( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', ' change_posts_order ' );

I hope this is what you are looking for and it will help you.

Otherwise Senpai @Anton might be able to help :grin:

Best regards

Özcan

Hi @redbranchmedia,

it will work this code.

I’ve created an extra module but you can do it directly in the listing HTML

{% set blog_tags = blog_tags('module.blog_field', 250) %}

{% set sorted_tags = blog_tags|sort(False, False, 'name') %}

{% set tag_posts = blog_recent_tag_posts(blog_tags, sorted_tags, 100)|sort(False, False, 'name') %}

{% for post in tag_posts %}
 <div class="post-title">{{ post.name }}</div> {# replace this with your single post layout #}
{% endfor %}

edit:

If you decide to create a custom module simply add a “blog” function. By default it will be called “blog_field”. If you give it a custom name replace it in the first line of code.

best,

Anton