annabelgregory
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: preventing emdash autocorrect in the content of postsThat’s brilliant – thank you so much! What a simple answer (I thought I was going to have to do loads of editing).
Thanks for the quick reply, too.
Forum: Fixing WordPress
In reply to: Remove sidebar from specific pageThanks.
Forum: Fixing WordPress
In reply to: Remove sidebar from specific pageThat works brilliantly! Thank you so much. Also, I didn’t expect such a quick response.
Ok, well I’m very pleased to say that the following seems to work, added to the functions.php file:
<?php function page_order_asc($query) { $query->set('orderby', 'post_date'); $query->set('order', 'ASC'); } add_action( 'pre_get_posts', 'page_order_asc'); ?>I did have an
if ( is_archive() ) { …. }
inserted as first line in the function, but this did not work, and really I want all posts sorted in ascending order whatever the context, so it is not needed.
Thank you for your help – I was baffled by it to start with, but with the additional help of the book Professional WordPress: design and development by Brad Williams et al, I have worked out something which seems to work. Phew!
- This reply was modified 7 years, 11 months ago by annabelgregory.
Sorry, I just remembered that I got a function from the Relevanssi plugin knowledge base to display search results in ascending order, and this works a treat. Can I modify it for the archives page? Code is as follows:
<?php add_filter('relevanssi_modify_wp_query', 'rlv_asc_date'); function rlv_asc_date($query) { $query->set('orderby', 'post_date'); $query->set('order', 'ASC'); return $query; } ?>Many thanks for this – but I’m afraid I do not understand! In the pre-get-posts reference that you give above, it says:
… pre_get_posts will not work if used in template files (e.g., archive.php), since they are called after the query has been completed. Unless you are intimately familiar with these settings and are willing to coordinate them, it’s suggested that you alter the main query for single page requests by using a new WP_Query in the page template itself.
So presumably you are suggesting that I put some code into functions.php, which is then called in archives.php? (or is it just picked up by reference?) Could you possibly spell out in more detail what you have in mind?