Returning data instead of echoing/printing

The problem with your code, as you mentioned, is that you are outputting the images via your print_r function, and you need to instead build a string to return, which is displayed in place of the shortcode. Give this a try: function get_media () { $attachments = get_posts([ ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ … Read more

Disable link for single posts

you can either disable click events using CSS. .linkclass { pointer-events: none;} Or better Modify the template and remove the part which creates anchor links for titles. note: with the above, it is still possible to access the page by directly putting the full URL in the browser. if you want to completely remove the … Read more

Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)

This is because you did not put singular.php in the URL, and if you did it wouldn’t make any sense. Remember, WordPress loads the template, not the other way round, your mental model of how this works is upside down. What’s going on? Why is singular.php the file being accessed while PHP prints that the … Read more

using is_paged for hiding image on posts

I read that it doesn’t work for posts using <!–nextpage–> Not necessarily, but basically, if the current URL ends with /page/<number> as in https://example.com/page/2/ and https://example.com/category/foo/page/2/, then is_paged() would work, i.e. it returns true on page 2, 3, etc. But for singular posts with a page break, i.e. the <!–nextpage–> tag, where the URL normally … Read more

Get all comments of author’s posts

It looks like there’s two problem with the code you’re trying to use. The first is AUTHOR_ID. Unless you have this defined somewhere else, then this is going to cause an undefined constant error. The second one is that there should be a closing PHP tag ?> before <?php endwhile; ?>. Another thing is, that … Read more

How to Get Posts, Including Private Ones?

Set the post_status argument to an array of desired post status strings, or to the string any to query regardless of status entirely: $posts = get_posts(array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ‘post_status’ => array( ‘publish’, ‘private’ ), ));

wp_insert_post_data: Limit number of Page but Post get affected

I would suggest one slight change to your logic as follows: function set_post_to_draft_page_only( $data, $postarr ) { if($data[‘post_type’] == ‘page’) { if( wp_count_posts(‘page’)->publish > 2 ) { $data[‘post_status’] = ‘draft’; } } return $data; } add_filter( ‘wp_insert_post_data’, ‘set_post_to_draft_page_only’, 99, 2 ); You were not returning $data if post type was anything other than ‘page’.

‘Organize Series Plugin’ as muti author feature

May I suggest using the Posts 2 Posts plugin instead. You can create a ‘serie’ custom post type, specifying the appropriate capabilites, which would allow authors to add descriptions, order posts using drag-and-drop, etc.: https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage https://github.com/scribu/wp-posts-to-posts/wiki/Connection-ordering