Execute PHP function inside the admin area

Hook into the admin_init action… add_action(‘admin_init’, ‘fetch_all_companies’); function fetch_all_companies() { //do something here… } note: What file are you running your fetch_all_companies() function from and where is it located (the path to the file)? Its likely the WordPress environment is not loaded on the destination file which is why your function appears to be undefined.

Get list of all Grandchild Pages

My current idea is: Use get_pages to get all of the descendants of TOP and put the IDs in an array arrayAll. Then run get_pages again with parent=1 to get just the direct children of TOP. Put these in array arrayChildren. Run in php arrayGrandchildren = array_diff(arrayAll, arrayChildren) to get a list of all pages … Read more

Start Query from 2nd Post without offset

With pagination is easy 🙂 -just retrieve all the posts, then skip the first one out. At the end rewind back to the beginning of the loop and output the post you missed out. if( have_posts() ): while( have_posts() ): the_post(); if( 0 == $wp_query->$current_post ) continue; // Display all but the first post endwhile; … Read more

Which is from this queries is more faster

These queries are the same – the only difference being the syntax. There’ll be no noticeable performance difference. I prefer the first for readability when it is formatted correctly. (Also, the first query doesn’t use the paged argument, so it won’t ‘paginate’ – but I guess that was omitted by mistake).

How to get latest post excerpt from a specific category?

Try this: $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $wp_query = new WP_Query(“category_name=$catName&paged=$paged&posts_per_page=1”); Basically, add the paged variable to the args — since it’s your home page, you could hard code it to equal 1, of course.

How to apply pre_get_posts to a custom query?

For some use cases, couldn’t you use $query->get() to target specific custom queries? For example: say you’ve got a custom query for a slider post-type. Perhaps something like this? function wpse64950_filter_pre_get_posts( $query ) { if ( ! is_main_query() ) { if ( ‘slider’ == $query->get( ‘post-type’ ) ) { // This is a query of … Read more