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

​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!

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 change the complete wordpress structure to show most recent posts according to last modified

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

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/

Wordpress: Different look for different posts

I've looked everywhere to work out how to do this, but I'm having no luck. I read up on Post Formats, but I don't think that's what I'm looking for.
All the posts on the frontpage are the same, but say, for features or reviews you can have an entirely different look compared to the "standard" single.php post.
Examples:
Homepage //
http:// ausdroid.net (All posts look the same)
Standard single post //
http://ausdroid.net/2013/02/03/samsung-galaxy-nexus-from-vodafone-receives-android-4-1-2-update
Different single post (for a review in this case) //
http://ausdroid.net/2013/02/02/huawei-ascend-d1-quad-review
Thanks!
Sample on using category to present different Singles:
single.php
<?php
if ( in_category( $foo ) )
require( 'single-foo.php' );
else
require( 'single-default.php' );
So you'll have the above simple code in the usual single.php, put your previous single.php to single-default.php, and create your "other" Single layout in single-foo.php.
$foo can be category ID or Slug.
in_category()
EDIT
You can modify this to work with Post Formats:
In functions.php:
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
... then, change the if statement in my sample above to use has_post_format() instead.
has_post_format().
http://www.wpbeginner.com/wp-themes/create-custom-single-post-templates-for-specific-posts-or-sections-in-wordpress/
this explains it pretty well using " Single Post Template" plugin, if thats an option
You can try adding custom fields to the posts and check them in the single.php to show different layouts. See this video for and example of a plugin doing just that - youtube.com/watch?v=L3VXnryN9iY

How to filter Wordpress posts using a hook in a plugin?

I'm creating a Wordpress plugin and, being a newbie in the development on this platform, I'm stuck on this problem.
I'd like to have posts in the loop filtered by categories, defined by the user through an admin page. I would actually like to be able to modify query_post() parameters in the plugin, but the only trick I found is to re-run the query_post() with my user-defined criteria, thing that I would like to avoid.
Also, due to the plugin nature, I think it make no sense to modify the theme's template.
I'm sure the solution is evident, but can't find it!
I thought there was a nicer solution, but this is how I finally solved it:
add_filter ( 'query_vars', 'myplugin_filter_posts');
function myplugin_filter_posts( $content )
{
//WP's query handler
global $wp_query;
//The id of the category whose posts I'd like to show
$catId = 1;
$result = $wp_query->query( 'cat='.$catId );
return $content;
}
If you tips for a better solution, please share :)

Resources