How to update serialized post meta?

You must read custom field themeOps first, update index option3 in array and then save/update whole array. $kisiArray = get_post_meta( $post_id, ‘themeOps’ ); $kisiArray[‘option3’] = ‘peach’; update_post_meta( $post_id, ‘themeOps’, $kisiArray ); Update (sort by custom field) $args = array( ‘post_type’ => ‘post’, ‘meta_key’ => ‘themeOps_option3’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ); $query = new … Read more

Replace existing pages with new pages, keep menu links

I was shocked to see that such a simple thing is not readily supported. I was even more shocked to see that no one had a good answer here on StackExchange! Happily, I found this post: https://wordpress.org/support/topic/updating-current-page-with-new-built-page/ …and am grateful for the answer provided by Joy (@joyously on WordPress.org and Slack) “If you need to … Read more

same template for multiple custom post type single

Yes, you can use template_include or the more specific single_template. Example code: add_filter( ‘single_template’, function( $template ) { $cpt = [ ‘america’, ‘nepal’, ‘norway’ ]; return in_array( get_queried_object()->post_type, $cpt, true ) ? ‘path/to/country-single.php’ : $template; } ); single_template filter runs only for singular queries, so you don’t need to check you are on a singular … Read more

Auto set Post to Specific Categories

Here is some rough code for you, you may improve the query if you like… By the way selecting post_title and post_status is not neccessary, but useful if you want to ensure that you are returning the right results via conditional logic within your foreach loop. global $wpdb; $results = $wpdb->get_results( ” SELECT ID, post_title, … Read more

get_permalink executes link without https

this may be called as a bug in get_permalink, but it may not be. I had the same case, and when I tried to echo site_url(); I get the https://… But once I updated the options for siteurl and home to have https get_option( ‘siteurl’ ); get_option( ‘home’ ); get_permalink worked fine. I noticed that … Read more

Slug for standard post post_type

WordPress offers you the ability to create a custom URL structure for your permalinks and archives. For this you will have to change permalink, Permalinks allows you to choose your default permalink structure. To change permalink go to Settings > Permalinks in WP Backend. Choose Post name In Common Settings Section.

Action on post publish

If your aim is to trigger code when a post is published, as in, the post_status of the post is set to publish, then you can hook into save_post like this: function cc_publish_wpse_263985( $postid ) { // check if post status is ‘publish’ if ( get_post_status( $postid ) == ‘publish’) ) { // do something … Read more