query if page has not child

$args = array( ‘post_status’ => ‘publish’, ‘post_parent’ => $post_id ); $children = get_posts( $args ); if( count( $children ) > 0 ) { //has children } else { //does not have children } Docs: get_posts() This should also allow you to have access to the data of the children, should you need it. If you … Read more

Order posts by recent comments

You can use the following code, which first gets the most recent comments, then using the post_ids associated with those comments, queries the database for those posts: // Get the 5 most recent comments $recent_comments = get_comments( array( ‘orderby’ => ‘comment_date’, ‘number’ => 5 ) ); // If there are any posts with comments if … Read more

Can’t seem to do combined query AND sort?

I had this same problem until I realized you don’t actually have to query by the event start date, only the end date. As long as the event’s end date has not past it doesn’t matter whether the start date is in the future or not. All you have to do is grab all the … Read more

List author’s posts with SQL

Your table names are wrong. note in your first query the use of $wpdb->posts to reference the posts table. however– this is a very simple query that can be done via the API rather than writing SQL queries from scratch. Use a new WP_Query instance instead.

wp_list_pages() refuses to output posts

wp_list_pages will only output hierarchical post types. If we look at the function in source, we’ll see that it calls get_pages to load pages for output. If we look at get_pages function in source, we’ll see: // Make sure the post type is hierarchical $hierarchical_post_types = get_post_types( array( ‘hierarchical’ => true ) ); if ( … Read more

Passing parameters to a static front page

front-page.php is a static front page (if you rename your current template front-page.php, and don’t select nothing in Settings->Reading it works exactly like now. However, if you want to use the page approach and you don’t use mcdata for query, remove the filter you posted, and simply retrieve the mcdata value in your template using … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)