the original .php part of my theme looks like this:
$bam_related_posts_taxonomy = get_theme_mod( 'bam_related_posts_taxonomy', 'category' );
$bam_post_args = array(
'posts_per_page' => absint( get_theme_mod( 'bam_related_posts_count', '3' ) ),
'orderby' => 'rand',
'post__not_in' => array( get_the_ID() ),
);
(*A lot of other codes here*)
wp_reset_postdata();
I added this part below the 'post___not_in' myself:
'category__not_in' => array(21),
This way, I exclude a certain category. It's working, however, I want to add this last part of the code in my own plugin, so it won't reset when I update my theme. How do I get this last line into the functions.php of my own plugin? Simply adding that line to it won't work, it needs to point to the rest of the code...
the original .php part of my theme looks like this:
$bam_related_posts_taxonomy = get_theme_mod( 'bam_related_posts_taxonomy', 'category' );
$bam_post_args = array(
'posts_per_page' => absint( get_theme_mod( 'bam_related_posts_count', '3' ) ),
'orderby' => 'rand',
'post__not_in' => array( get_the_ID() ),
);
(*A lot of other codes here*)
wp_reset_postdata();
I added this part below the 'post___not_in' myself:
'category__not_in' => array(21),
This way, I exclude a certain category. It's working, however, I want to add this last part of the code in my own plugin, so it won't reset when I update my theme. How do I get this last line into the functions.php of my own plugin? Simply adding that line to it won't work, it needs to point to the rest of the code...
Share Improve this question asked Mar 14, 2020 at 15:30 IzzyIzzy 1 2 |1 Answer
Reset to default 0You don't, what you've modified is a template file, those don't go in plugins.
Instead, create a child theme and copy this file into that theme. WordPress will preferentially load templates from the child theme, falling back to the original parent theme. This way any modifications you make in the child theme will overwrite the parent, and if the parent is updated no changes are lost
__not_in
type parameters are extremely expensive/slow those queries are very heavy on the server – Tom J Nowell ♦ Commented Mar 14, 2020 at 15:49