Display only posts from a specific parent category

$the_category_id = 10; $new_posts = new WP_Query( array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘terms’ => array( $the_category_id ), ‘field’ => ‘term_id’, ‘operator’ => ‘AND’, ‘include_children’ => false ) ) ) ); So basically the difference is include_children parameter.

Dynamically update post title in admin page

The block editor is restoring back the title that was last saved (or typed manually into the textarea), so with the block editor, you can change the title dynamically using this code: wp.data.dispatch( ‘core/editor’ ).editPost( { title: ‘Title here’ } ) PS: You should make sure your JS file has the wp-editor, wp-edit-post or wp-data … Read more

Downloadable Documents

No need to insert the download into the post as @kaiser says, you can automate: $download = get_children( ‘post_type=attachment&post_mime_type=application/pdf&post_parent=”.$post->ID ); if ($download) { foreach ( $download as $attachment_id => $attachment ) { echo “<a href=”‘.wp_get_attachment_url($attachment_id).'” target=”_blank” class=”download”>Download PDF</a>’; } }

Display posts by tag on page

This should do the job. It’ll check for posts that have been tagged with the title of the current page. There’s no need to use if (have_posts()): on a page template: if the template is called it will be because there is a post 🙂 <div class=”page-loop”> <?php while (have_posts()) : the_post(); $page_title = strtolower(get_the_title()); … Read more

Get names of authors who have edited a post

The WordPress function get_the_modified_author() will give you the author who last edited the current post. But if you want to list all the users that have edit the current post, you could try: function get_the_modified_authors_wpse_99226(){ global $wpdb; $authors = array(); $results = $wpdb->get_results( $wpdb->prepare(“SELECT post_author FROM $wpdb->posts WHERE (post_type=”%s” AND ID = %d) OR (post_type=”revision” … Read more

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