How to change the complete wordpress structure to show most recent posts according to last modified - wordpress

In wordpress blog, posts appears according to most recent (new). Here i want to change it to show all recent posts according to last modified. Does it possible?
I don't know where the code is, checked theme functions but not found anything.
Can anyone help me?

You need to use this hook to get the post order by last modified.
function custom_loop( $query ) {
$query->set( 'orderby', 'modified' );
}
add_action( 'pre_get_posts', 'custom_loop' );
Use this in functions.php

Related

pre_get_posts not limiting posts per pages

I have set up the following in my functions.php to raise the limit of posts being shown when doing a public search:
if ( ! is_admin() && $query->is_search) {
$query->set('posts_per_page', 20);
}
}
add_action( 'pre_get_posts', 'search_results_query' );
But however much I tried to modify it, I don't seem to have any effect. What am I missing?
You are missing part of your code but do you have $query set to pass through your function?
function search_results_query( $query ) {
I just tested your code and set it to 1 using the 2019 theme and it worked fine with the above.
Thank you, the problem was that the theme had already set the posts per pages. I managed to change the number of posts from the appearance menu. The page template had already theme actions and hooks and I have a limited understanding yet of it all, but I think that was what was interfering with my hook. Or I just simply didn't understand fully how to hook it up properly. Either way, I resolved it.

How to hide a specific category name everywhere on this theme?

​Hello,
I know this isn't a new topic and it has been already discussed but I need to hide the name of a specific post category named "Nolink" from anywhere on the website and after trying several things, nothing seems to work.
I don't know if it's because the theme I'm using: http://bridge92.qodeinteractive.com/ but can't find the way to make it work.
Any ideas?
Thanks in advance
Simple solution via editing the functions.php file:
function exclude_category( $query ) {
$query->set( 'cat', '-4' );
}
add_action( 'pre_get_posts', 'exclude_category' );
What this will do is omit a specific post category from the global get post query. Be sure to replace the "4" with the ID of your category you want to omit. Hope this helps!

Auto-formatting in Wordpress posts only

I'm using remove_filter( 'the_content', 'wpautop' ); in my theme in order to disable Wordpress auto-formatting that adds paragraphs everywhere and often messes up the layout.
However, one of my clients wants to be able to add blog posts on his own. He needs to be able to format his blog posts from the WYSIWYG editor, minimally to have paragraphs.
Is it possible to allow the auto-formatting in blog posts only, or in posts of a particular type or belonging to a particular category?
So far all examples and articles I found use the exact same code as the one listed above. I also checked the https://codex.wordpress.org/Template_Tags but didn't see anything there that could help me solve this.
So now that you've removed the regular wpautop filer, you could add your own in its place, and in it, only apply the wpautop only on posts of type "post":
add_filter( 'the_content', 'smart_autop' );
function smart_autop($content) {
$post = get_post();
if($post->post_type != 'post') return $content; // if not a post, leave $content untouched
return wpautop($content);
}
Hope this helps!

Sensei and Woocommerce checkout notices - remove action

First question so please be patient!
I'm using Sensei and Woocommerce for an LMS and payment portal site.
When the checkout is complete and a course (from Sensei) has been purchased I want to remove the notice created by Sensei and the top of the page.
It is added with this action.
add_action( 'template_redirect', array( 'Sensei_WC','course_link_from_order' ) );
Therefore, how do I remove or change this notice created by the action
I've tried this!
remove_action( 'template_redirect', array( 'Sensei_WC','course_link_from_order' ) );
in my functions file by alas, no success!
Thanks in advance

Wordpress search doesn't show custom post types and fields

I have done some research on this topic and followed many tutorials but nothing seems to work, I was wondering if someone could help me out? I want to allow the search form in my Wordpress site to also include custom post types and custom meta fields. I would really appreciate it if someone could help me out. THANKS!
Archives.php only shows content of type 'post', but you can alter it to include custom post types. Add this filter to your functions.php file:
function namespace_add_custom_types( $query ) {
if ( $query->is_search )
$query->set( 'post_type', array( 'post', 'YOUR_CUSTOM_POST_HERE') );
return $query;
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
Wordpress search functionality looking search query only in 'posts' table in DB, but custom fields are saved on 'post_meta' table. So, firstly you need to LEFT JOIN these two tables, secondly change query to DB, and finally - prevent duplicates in searching. Please look at this link, here is the code you must paste into functions.php with an explanation -> https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/

Resources