How to ignore posts in pre_get_posts?

What about this one? function opby_query( $query ) { if ( $query->is_main_query() ) { if ( $query->is_home() ) { $query->set(‘posts_per_page’, 15); }; if ( isset( $query->query_vars[‘ctrl_podcasts_status’] ) ) { // get main query args $subquery_args = $query->query_vars; // add tax_query filter $subquery_args[‘tax_query’] = array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array( ‘podcast-control-daily’ … Read more

Two functions with different arguments and add_actions, but identical code

If I am not missing something here, you could have a third/main function, with two different wrappers for it. function wpse381184_main(){ //do your thing! } function acp_editing_saved_usage1( AC\Column $column, $post_id, $value ) { // call wpse381184_main() wpse381184_main(); } add_action( ‘acp/editing/saved’, ‘acp_editing_saved_usage’, 10, 3 ); function my_acf_save_post( $post_id ) { // call wpse381184_main() wpse381184_main(); } add_action(‘acf/save_post’, … Read more

Running script based on Category

run only on posts listed under one category I highlighted that “posts” because if so, then the conditional tag you should use is in_category() and not is_category() which is for category archive pages (e.g. example.com/category/foo) — so for example, is_category( 93 ) checks if the current archive page is for the category (with the ID … Read more

Is There Any Built In WP Functionality For Combining Form Fields To Return Specific Data

You can do this with basic input fields and the URL. This is because example.com/?s=test is a search URL for “test”, but example.com/category/foo/?s=test also works, and searches the foo category. Likewise, most of the other parameters WP_Query takes also work, e.g. post_type. If we dig a bit deeper, all the pretty permalinks, and WP rewrite … Read more

Cannot declare function twice [closed]

I agree with Pat in the comments: the easiest thing to do would be to rename the function in one of the two snippets, changing the name both on the function definition and the add_filter line. But if you did want to combine the two into a single snippet you could do something like this: … Read more

Setting a default text for excerpts of a particular category

Insert the following code, in functions.php of your child theme. function wpse_excerpt_for_specific_category( $excerpt ) { global $post; $category = ‘Test’; // could be name, slug, or id $excerpt_text=”some arbitrary text”; if( ‘post’ == $post->post_type && ‘publish’ == $post->post_status && in_category( $category ) ) { $excerpt = $excerpt_text; } return $excerpt; } add_filter( ‘get_the_excerpt’, ‘wpse_excerpt_for_specific_category’ ); … Read more