Show the entries in alphabetical order in the WordPress loop

By default, the loop from WordPress will display your blog entries in chronologically inverse mode so that your last entry will be shown higher than the previous ones, but sometimes it may be interesting to skip this convention and display them alphabetically .

Either to create an alphabetical index where each entry is one of the definitions, or a glossary, or any type of publication that requires entries to be shown alphabetically is an option to take into account for the day you want to use this possibility in a project.

Category file in alphabetical order

An example would be to show some specific category in alphabetical order. For this we should edit the file of the template of the categories, normally category.php and add something before loop like this:

Cover in alphabetical order

On the other hand, if what you want is show the loop of the cover in alphabetical order instead of chronologically invers or, in this case what we will do is modify the main WordPress requests ( pre_get_posts and is_main_query ).

But in this case it is not necessary to edit the file with the loop cover but it is better to do it forcing the modification from a file of functions ]either an own plugin or the file functions.php of the active theme.

We did this by adding this to the chosen one:

This function will edit the main request before it is executed, and will make sure that wherever the main request of the entries, such as in index.php entries are shown alphabetically .

Loading …

may also help you:

Move comments from one entry to another • WordPress Help

 man bullet

There are not many occasions when you might need to move comments from one entry to another but if you get the " need " at least you must be calm, there is only one way, but several, to get it.

And that is, either by a redirection of entries, where you would lose the positioning offered by comments, or by an error of a user commenting where it should not, or simply because it seems good, move comments from one entry to another is not only possible, it is also quite easy but not be a WordPress default option.

:: Move comments with SQL ::

If you dare to move them by SQL it only takes 3 steps:

  1. The first thing is to locate the ID of the entries, the old one and the new one, something you can easily identify in the e-administration screen ntradas, simply placing the cursor on them and looking at the number that appears in the browser's status bar. Other modes would be to use the plugin Show IDs or add a column to display the IDs . Record the numeric IDs as you need them for the second step.
  2. Access PHPMyAdmin and, in your database, create the following query SQL:

    If you only want to move the comments of an author, it would be this way:

  3. With the previous step you have moved the comments but you must also change the comment counter, because WordPress does not he does it on his own. So we finish the sequence with this new query SQL:

    Of course, in queries you must replace the s conventions by the numbers of the corresponding IDs and the numbers of the comments, of course.

 query sql phpmyadmin wordpress

:: Move comments with plugins ::

If you do not feel comfortable with SQL there is no problem, you can always use plugins that make life easier in this work, not common, but important when you need it.

  • Tako movable comments : Absolutely perfect, not only allows you to move comments in bulk from an entry to another without having to know the ID, thanks to convenient drop-down, but also allows to move a comment (and its nested) from one entry to another in a simple way. It offers everything you're used to in the forums software and more.
  • Move comments : simpler than the previous one, it only allows you to move all comments from one entry to another. That yes, functional, simple and effective.
  • Simple move comments : Even more simplified version of the previous but equally effective.

 move comments wordpress

:: Move comments with trick ::

Now, if you're one of mine and you like to mess up and make your " ñapas ", nothing better than a trick with which you do not have to do queries or install plugins, you just use WordPress to the brave .

The idea is simple: cheat WordPress . And the sequence is this:

  1. Go to the input editing screen and press the " Quick Edit " button of the old entry. Change the title, the " slug " and the date and time (to which you want, as long as it is not the same). That's right, take note of the previous exact values ​​(title, slug and exact date and time)
  2. Now do a " Quick Edit " of the new entry and put the same title, slug date and time of the old one.

 quick edit entry to move comments

It looks like a dumb but it works, even on and similar accommodations

NOTICE : This publication is from two years ago or more. If it's a code or a plugin it might not work in the latest versions of WordPress, and if it's a news story it might be obsolete. Then do not say we have not warned you.

Loading …

That may also help you:

QueryPosts, as the WordPress Codex should be

The Codex is the WordPress Bible but I've always thought that it lacks functionality for to quickly document any function or hook needed to program.

If I had to choose the next Codex tool I know it would be something very similar to QueryPosts .

QueryPosts is a website that offers a predictive search (shows results as you type) of WordPress functions and, once you have identified the one you want, then, first, a list of the arguments that you can use, as well as the path where " call "to the function.

In that screen, in addition, you can click on the function name, and then have a very complete screen in which we describe the same, its uses and we are given up to the. Everything very visual, simple and usable.

Come on, what the Codex should have, do not you think?

Limit searches only to titles in WordPress

Sometimes the WordPress search engine becomes too little useful, and it's not that it does it badly, but it's not as specific as it could be, depending on what moments.

One possible need, if it has arisen, it would be that the internal WordPress search engine only searches the titles which is what the user normally agrees.

If this is your case, you can modify the behavior by default of the internal WordPress search engine. Just add this code to your function plugin or file functions.php of your active topic:





















21 [19659002] 22





// Search only in titles

function __ search_by_title_only ( $ search & $ wp_query )


if ) [ empty ( $ search ) )

return $ search ; // stops processing if there is no term in the query

$ q [19659038] = & $ wp_query -> query_vars ;

// wp-includes / query.php line 2180 (en version 3.3)

$ n = ! empty ( $ q [ 'exact' ]] ) ? '' : '%' ;

$ searchand = '' ;

foreach (

( array ) $ q [ 'search_terms' ] as $ term ) {

$ term = esc_sql ( like_escap ( $ term ) ) ;

$ search ] . = "{$ searchand} ($ wpdb-> posts.post_title LIKE '{$ n} {$ term} {$ n}') ";

$ searchand = 'AND' ;

}} [19659000] $ term = esc_sql ( like_escape ( $ q [ 's '] ) ) ; [19659000] if ] [] ( $ q [ 'sentence' ] ) && count ( $ q [ 'search_terms' ] ) [19659038]> 1 && $ q [ 'search_terms' ] [ 0 ] ! = $ [ 's' ] )

$ search . = "OR ($ wpdb-> posts.post_title LIKE '{$ n} {$ term} {$ n}')" ;

if ( ! empty ( $ search ) ) ] {

$ search = "AND ({$ search})" ; ]

if ( ! is_user_logged_in () )

$ search [1945902] 4] . = "AND ($ wpdb-> posts.post_password = '')" ;

} [19659000] return $ search ;


add_filter ( 'posts_search' '__ search_by_title_only' 10 2 ) ;

You save the changes and you already have it. Now it will only search the titles of your tickets.

Show advertising only on old WordPress entries

I guess you already know that after some time, normally days, the visitors that arrive to your website come mostly from search engines . And this means several things, namely:

  • They are not faithful visitors, your readers visit you every day
  • The time of stay is low
  • They do not usually leave comments, and it's almost better that they do not
  • The ratio of clicks on the ads is usually higher than that of regular visitors

… among many other things.

So why not develop a strategy for this type of visits? , for example with advertising. Because you already know that regular visitors do not like advertising that they already honor you with their daily presence, but surely with occasional visitors if we can make an exception.

And a way could be to configure our WordPress so that entries with a few days old display some special text, such as ads that normally would not disturb your daily visitors.

The first step is to add the following code to the file functions.php of your active theme or to your function plugin :

In this example the code makes a query to detect the date of each entry, and it will work in entries more than 30 days old and if you want to change it you only have to modify the string ] $ days of line 2.

You save and now you can put a code of this style in your theme, on the site (usually in single.php ) where you want it to be displayed advertising – only old tickets: