How do I split a large query with a semi-expensive function included into multiple smaller queries

Yes, using ‘posts_per_page’ => -1 is a bad practice as it loads every matching post from the database, which can mean hundreds, thousands or millions of entries in the worst case. And it looks like you only need post ID’s in your code, not the whole post objects. This means you can slim down the … Read more

html sitemap via recursive function

The “memory exhausted” error in question happened because of this part in your function: ‘parent’ => $next_page -> post_parent, which should actually be ‘parent’ => $next_page -> ID (or I’d omit the unnecessary spaces, i.e. I’d use ‘parent’ => $next_page->ID). And the error can be illustrated like so: $cur_page = get_post( 123 ); // assume … Read more

logrotating files in a directories and its subdirectories

How deep do your subdirectories go? /var/log/basedir/*.log /var/log/basedir/*/*.log { daily rotate 5 } Will rotate all .log files in basedir/ as well as all .log files in any direct child of basedir. If you also need to go 1 level deeper just add another /var/log/basedir/*/*/*.log until you have each level covered. This can be tested … Read more

wp_insert_post wrong post type [closed]

The problem is that your code creates a post if the created post is not manually-published, but the new post is automatically-published, and those don’t match. Your conditional is not explicit enough and eneds to skip the scenario when your inserted post is inserted to prevent an infinite loop Instead of: function create_auto_post($post_ID) { if … Read more

Pushing stored procedure to a multisite database in WordPress

Here are the Steps: STEP 01 : Put code in a Text File Open up a text editor (vi, nano, emacs) and place your code in it. Save it as /tmp/mynewcode.sql STEP 02 : Collect All Databases Names MYSQLCONN=`-uroot -ppassword` SQLSTMT=”SELECT schema_name FROM information_schema.schemata” SQLSTMT=”${SQLSTMT} WHERE schema_name NOT IN” SQLSTMT=”${SQLSTMT} (‘information_schema’,’performance_schema’,’mysql’)” mysql ${MYSQLCONN} -ANe”${SQLSTMT}” > … Read more