OK, how about this then? (Changed from first try – now tested.)
function my_post_queries( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( is_category( 7 ) ) {
$query->set( 'posts_per_page', 6 );
}
//works with pretty permalinks
$cat_id = get_queried_object()->term_id;
if ( cat_is_ancestor_of( 7, $cat_id ) ) {
$query->set( 'posts_per_page', 12 );
}
}
}
Note: Still not sure about the purpose or effect of including return ;
‘s. Had no obvious effect on functionality, so have left them out.
Related Posts:
- remove empty paragraphs from the_content?
- wp_enqueue_script was called incorrectly
- Add multiple custom fields to the general settings page
- Set JPEG compression for specific custom image sizes
- Prevent “main” WPMU site_url() being returned in functions
- Display custom comments field for first level only
- bloginfo() vs get_option?
- Get recent posts with thumbnail
- Display Total Number of Social Shares
- how to create shortcode in wordpress
- Child theme – copied some files from parent to child website still uses parent files
- Function returns different value when called from ‘save_post’ than when called on page load
- Using locate-template & shortcodes doesn’t appear to work
- Widgets Section not displaying in theme customizer
- add sidebar area to header of child theme
- Displaying a random user with a shortcode
- Display a function using AJAX
- How to make unique add_filter to the_content of specific page template files – so each template gets its own addition
- Hide the Private prefix on one specific page
- Updating users_can_register option?
- How to test for Super Admin
- Adding a class to tag list in a function
- img width and height attributes being set by get_the_post_thumbnail
- echo get_post_meta()
- Replace menu links with # and add name to its li
- Custom function in My Custom Functions returning 403
- Retrieve tags data in post body
- Remove H1 / title / Underscore – without CSS
- Custom Static Links For Specific Menu Right Before/Next The wp_nav_menu Function now working
- functions.php How to add css/js depending on Template Name?
- Change template on the fly based on post parent selection
- Current path on page in functions.php
- How do you publish a draft on WordPress
- How can I recompile js file in dist folder?
- Show Primary Category first when I display post categories
- Wp_query function to search from product_title ‘OR’ product tags name
- Getting custom image size URL in functions
- Unique sequential reservation code
- new_excerpt_more link not working properly
- Where to add the permalink in this function?
- WordPress function saves a post twice and updates all posts
- Change CSS for logged in users
- Always the Latest google jQuery instead of default WordPress jQuery
- if statement for wordpress default featured image on single post
- Function to display post by specific author
- Override the WordPress core function wp_referer_field
- Return category name with & Ampersand doesnt work
- Control the srcset much more (not all sizes in it each time)
- Warning: join(): Invalid arguments passed in post-template.php
- javascript and css links not working on sever
- is_page() or is_single not working
- What are the meta fields for an attachment?
- Can’t locate custom image sizes defined by child theme
- how to change “posted by” words
- Add attribute only to first image of every post via functions.php
- 400 Bad Request – JavaScript App calling Custom wp-json endpoint
- Adding product to WooCommerce cart [closed]
- Add loggedout class on body using a function or JS
- Insert a field with PREG_REPLACE – strange behaviour
- Difference between get_userdata() and get_currentuserinfo()
- Help with IF has focus then… statment
- How d0 i get the number of attachments in the post
- Astra theme – cannot set short product description under the product title (product name)
- Is posible to redirect a few URL?
- Default click “I have read and agree to the website terms and conditions”
- How to use wp_enqueue_script properly?
- Run function with schedule is not working correctly
- Enqueue script if not page template
- I have defined 2 text strings, how do I use them in my posts?
- Images with overlay
- Create New User Custom Field not Saving
- Keep Admin Logged In For a Year
- Changing author links on homepage to buddypress profiles – without affecting ability to link to author archive throughout the site
- WordPress Ajaxifying not working properly
- Strange result of get_stylesheet_directory()
- Comment function for page
- Using a variable in name of dynamically-called helper function
- Taxonomy On Index Page
- How to add function to custom fields when page/post has a password?
- Zip all (original) images from media gallery
- How to exclude posts with empty and non-existent relational custom field with meta_query?
- custom COOKIE on custom page
- List all post title in category using functions.php
- Quicktags external functions file
- Problem in shortcode outputting content
- Remove Captions from Custom Gallery function.php
- Optimizing multiple WP_querys into one call?
- Why does modifying my functions.php file always result in a server error
- How do I get my nav menu to show sub pages?
- Gallery Shortcode Function Help
- Echo custom field value in shortcode function
- WordPress Comment functions
- How do I add e-mail subscription functionality
- wp_get_current_user->user login returns %20 for spaces
- Disable every rss feed except home feed
- reusing code in function and running it with loop
- Explode Array from Repeatable Custom Field
- Automatically delete posts that aren’t in an array
- Ads Only at one website inside multisite network – code error
- Get all users from role and add to dropdown (select) – wordpress, javascript