Should I create Custom Page Types?

You’ve highlighted the issue of creating custom post types in a theme rather than in a plugin. If the user changes to a new theme then you cannot rely on any functionality in the theme you have created. Themes can add functionality, but in general should be concerned with the presentation of your site Plugins … Read more

WordPress wp_query() basic question about args

Your 3rd option is correct. $args3 = array( ‘posts_per_page’ => 9, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, // If you’re only specifying one. Use array( ‘projects’, ‘post’ ); for many. ‘post_type’ => ‘projects’, // This is the correct syntax for a taxonomy query. ‘tax_query’ => array( array( ‘taxonomy’ => ‘projects_categories’, ‘terms’ => $cat_id, ), ), … Read more

Create custom post with meta field with AJAX and the WordPress REST API

I haven’t tested your code, but here the $object is an object and not array: // Here, $object is a WP_Post object. function slug_update_post_meta_cb( $value, $object, $field_name ) { return update_post_meta( $object->ID, $field_name, $value ); } And you can actually use register_meta() with a custom post type: register_meta( ‘post’, ‘myfield’, [ ‘object_subtype’ => ‘custom_type’, // … Read more

Rename a slug label

As SallyCJ mentioned, gettext is really the only option you have with this, because the Slug labels are hardcoded in the Core of WordPress. https://core.trac.wordpress.org/browser/tags/5.2/src/wp-admin/edit-tags.php#L439 Here is a snippet I wrote and tested that should work for you, and it will only run on the backend and only on the two pages where you will … Read more

Custom rewrite to fetch feed data

Seems like a good candidate for add_rewrite_endpoint(). add_rewrite_endpoint( ‘items’, EP_ROOT, ‘item_id’ ); That will register the endpoint /items/<item ID> and also registers the query var item_id, and eliminates the 404 status header/title as well. But the page title would be the site name and you’d probably still want to hook to pre_get_document_title to customize the … Read more

How can I group posts by months and years?

You can do it like so: global $post; $posts = get_posts( array( ‘post_type’ => ‘press’, ‘nopaging’ => true, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, // it’s DESC; not DSC // There’s no use setting posts_per_page when nopaging is enabled. // Because posts_per_page will be ignored when nopaging is enabled. ) ); $_year_mon = ”; // … Read more