Want to build parent-child relationships between custom post types created with CPT UI

I’ve gone through similar queries from the past but couldn’t find a solution that works for me.

So I created 3 different custom post types with the CPT UI plugin. They are called ‘careers’, ‘vacancies’, ‘our-staff’, respectively.

What I want to achieve is set ‘careers’ as the parent, and both ‘vacancies’ and ‘our-staff’ as children of ‘careers’, so that the breadcrumb lists on the children pages dynamically show as follows:

Home > Careers > Vacancies

Home > Careers > Our Staff

In the CPT UI interface, hierarchical is set to ‘true’ for all 3 custom post types.

For the two intended children pages ‘vacancies’ and ‘our staff’, ‘Parent’ is set as ‘careers’.

However the breadcrumb lists on the intended children pages still show as

Home > Vacancies

Home > Our Staff

i.e. skipping the parent page.

When I try getting the parent page ID of the children pages, it shows as "0" meaning the parent page is not set as intended.

I’ve tried using the Add-Hierarchy-Parent-to-Post plugin, but no luck….

Would be grateful for any tips, including workarounds to get the result I am hoping for.

How to get Relationship Field dual-column showing IDs instead of post titles in ACF plugin?

by default, in the ACF plugin, the relationship field allows the user to choose a relation with another post in the default dual column view. In my case, I am using the Relationship field in order to connect dealer post-types to products.

Since I am importing Product data from CSV, I would need to import Relationship fields as well, and I am doing this using WP All Import Pro plugin. If I try to export a product in order to create the proper CSV format, I can see all set up relationships using the Dealer post-type title. I would need to type in CSV the dealers IDs instead of their full title, because the titles could change at some point.

Is that something possible through a function? Also, apart from dealers IDs, is it possible to achieve using another IDs set up using ACF (that is to say, another ID which is not the default one assigned by WP)?

For now, I am using Post Object return format, I’ve tried with Post ID return format but does not work (I am not sure if this could work since I am trying to do something out of my knowledge…).

Thank you in advance, nflor

Display wp post views only if it’s more than 1000

I paste this code to my functions.php

function getCrunchifyPostViews($  postID){ $  count_key = 'post_views_count'; $  count = get_post_meta($  postID, $  count_key, true); if($  count==''){     delete_post_meta($  postID, $  count_key);     add_post_meta($  postID, $  count_key, '0');     return "0 View"; } return $  count.' Views'; }  function setCrunchifyPostViews($  postID) {     $  count_key = 'post_views_count';     $  count = get_post_meta($  postID, $  count_key, true);     if($  count==''){         $  count = 0;         delete_post_meta($  postID, $  count_key);         add_post_meta($  postID, $  count_key, '0');     }else{         $  count++;         update_post_meta($  postID, $  count_key, $  count);     } }   remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); 

and this code to single.php:

<?php           setCrunchifyPostViews(get_the_ID()); ?> 

and it too:

<?php           echo getCrunchifyPostViews(get_the_ID()); ?> 

The post view is working fine, but I would like to display on single.php if the current post views is more than 1000. Any idea how can i made it?

How add Filter by Tags and by categories to custom post type in Gutenberg block

I need to add Filter by Tags and by categories to custom post type in Gutenberg block. I have created a CPT called "newsfeed" and it is displayed correctly in the page editor as shown in the following image.

newsfeed

but does not have the options Filter by Categories and by Filter by Tags like in the post type "Posts".

What can I do to enable these options?

posts

This is the code I use to create the newsfeeds

function add_tags_categories_taxonomy_x5642() {     $  labels = array(         'name'              => _x( 'Feed Tags', 'taxonomy general name' ),         'singular_name'     => _x( 'Feed Tag', 'taxonomy singular name' ),         'search_items'      => __( 'Search Feed Tags' ),         'all_items'         => __( 'All Feed Tags' ),         'edit_item'         => __( 'Edit Feed Tag' ),          'update_item'       => __( 'Update Feed Tag' ),         'add_new_item'      => __( 'Add New Feed Tag' ),         'new_item_name'     => __( 'New Feed Tag' ),         'menu_name'         => __( 'Feed Tags' ),     );     $  args = array(         'labels' => $  labels,         'show_ui' => true,         'show_in_rest' => true,         'show_admin_column' => true,         'query_var' => true,     );     register_taxonomy('feeds_tags', 'newsfeed', $  args);          $  labels = array(         'name'              => _x( 'Feed Symbols', 'taxonomy general name' ),         'singular_name'     => _x( 'Feed Symbols', 'taxonomy singular name' ),         'search_items'      => __( 'Search Feed Symbols' ),         'all_items'         => __( 'All Feed Symbols' ),         'edit_item'         => __( 'Edit Feed Symbols' ),          'update_item'       => __( 'Update Feed Symbols' ),         'add_new_item'      => __( 'Add New Feed Symbols' ),         'new_item_name'     => __( 'New Feed Symbols' ),         'menu_name'         => __( 'Feed Symbols' ),     );     $  args = array(         'labels' => $  labels,         'show_ui' => true,         'show_in_rest' => true,         'show_admin_column' => true,         'query_var' => true,     );     register_taxonomy('feeds_symbols', 'newsfeed', $  args);      register_taxonomy_for_object_type('category','newsfeed'); } add_action('init', 'add_tags_categories_taxonomy_x5642');  function add_feed_post_type_x1234($  query) {     if ( is_home() && $  query->is_main_query() ) {         $  query->set('post_type', ['post', 'newsfeed']);     }     return $  query; } add_action('pre_get_posts', 'add_feed_post_type_x1234'); 

Link custom post type to users membership

I’m building a medical lab site, I’d like to link a custom post type – results to users. How can I link results CPTs to a user?

The idea is to be able to associate multiple test results to a single user/member. Currently using woocommerce membership to power the membership.

Please, any idea(s) or just point me in the right direction would be helpful. Thank you in advance!

Is there a way to grab the current value of the editor in Gutenburg/Classic WordPress editor? (Not the saved value of the post!)

I’m trying to make my plugin "Gutenburg – compatible". I have some issues when replacing the editors contents. Before I could just change value by using #content but with Gutenburg there’s obviously a new approach with REST API.

Is there a way to grab the current value of the editor? (Not the saved value of the post!)

I want this because I want to replace values of the core/editor in realtime. It works with the classic editor active but I don’t want to require that.

let old_content = ''; old_content = wp.data.select( 'core/editor' ).getCurrentPost().content;      //TINYMCE => old_content = $  ('textarea#content').html();  //Aim is to do a replace like this (and this works but only FIRST time because old_content  //fetches from server/db instead of the actual editor (If I understand this correctly)  wp.data.dispatch( 'core/block-editor' ).resetBlocks( wp.blocks.parse( new_content ) ); //TINYMCE: $  ('textarea#content').html( new_content ); 

Edit Post with a parameter in URL

I was thinking in a way to make the editors have a quick way to access the current post editor.

I know we can manage this by showing a Link and make some conditionals to show to some users and login in users, but it would be cool to have something like this.

I thought first in something like:

add_action('init', 'edit_post_please'); function edit_post_please() {     if (is_user_logged_in() && current_user_can( 'edit_posts' )) {         $  protocol = ((!empty($  _SERVER['HTTPS']) && $  _SERVER['HTTPS'] != 'off') || $  _SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";         $  url = $  protocol . $  _SERVER['HTTP_HOST'] . $  _SERVER['REQUEST_URI'];              $  id = url_to_postid($  url);           $  parts = explode("/", $  url);         $  editor = end($  parts);         $  editor_link = get_edit_post_link($  id);          if ($  editor == '?editor') {             wp_redirect($  editor_link);             exit;         }     } }  

I haven’t think about the security issues or anything else this code does’t seem to work at all, I mean it redirects well to Dashboard but not to post I would like to edit.

$ editor_link have the correct edit url, but seems that this could be a restriction of WP?

Validate nonce with post ID in AJAX

I’m trying to create a nonce in an AJAX form where I can pass in a post ID. Then, validate it of course.

I want to confirm that if the action is intended, but also the post ID so someone cannot just change the POST ID input field value and take control of another post.

Here’s the nonce on the front end:

wp_create_nonce('my_edit_post' . $  post_id); 

And backend action:

add_action('wp_ajax_my_edit_post', 'handle_edit_post_form'); add_action('wp_ajax_nopriv_my_edit_post', 'handle_edit_post_form');  function handle_edit_post_form(){    if( ! isset( $  _POST['edit-post-nonce'] ) || ! wp_verify_nonce( $  _POST['edit-post-nonce'], 'my_edit_post')){      //failed   }   else {      //validated   } 

The whole thing doesn’t work because the $ post_id is not in the backend action.

But how can I pass it in there? $ post_id is undefined in the backend action.

The post ID is going to be dynamic (and not the referer URL’s ID).

how to display image in custom post type from frontend form using advanced custom field?

here is my code: employeedetails.php

<div class="container submit-message">     <h1>Employee Form</h1>     <form id="enquiry_email_form" action="#" method="POST" data-url="<?php echo admin_url('admin-ajax.php'); ?>" enctype="multipart/form-data">     <div class="form-group">             <label for="">Enter Title</label>             <input type="text" class="form-control" name="title" id="title"/>         </div>         <div class="form-group">             <label for="">Enter Description</label>             <input type="text" class="form-control" name="description" id="description"/>         </div>         <div class="form-group">             <label for="">Enter Your Name</label>             <input type="text" class="form-control" name="post_name" id="post_name"/>         </div>         <div class="form-group">             <label for="">Enter Your Designation</label>             <input type="text" name="post_designation" id="post_designation" class="form-control"/>         </div>         <div class="form-group">             <label for="">Salary</label>             <input type="text" class="form-control" name="post_salary" id="post_salary"/>         </div>         <div class="form-group">             <label for="">Enter Joining Date</label>             <input type="date" class="form-control" name="post_date" value="<?php echo date('Y-m-d'); ?>" id="post_date"/>         </div>            <div class="form-group">             <label for="">Select Image</label>             <input type="file" id="post_img" name="post_img" src="<?php bloginfo('template_url'); ?>" value="" accept="image/*""/>         </div>         <div class="form-group">             <button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-pencil"></i> Submit</button>         </div>     </form> </div> 

$ (document).ready(function() { $ (“#enquiry_email_form”).on(“submit”,function(event){ event.preventDefault(); /* Clear result div $ (“#data”).html(”); */ var form= $ (this); var ajaxurl = form.data(“”); // var image = $ (‘#post_img’).prop(‘files’)[0]; var post_title = form.find(“#title”).val(); var post_description = form.find(“#description”).val(); var post_name = form.find(“#post_name”).val(); var post_designation = form.find(“#post_designation”).val(); var post_salary = form.find(“#post_salary”).val(); var post_date = form.find(“#post_date”).val(); var post_img = form.find(“#post_img”).val(); /*console.log(post_title); console.log(post_description); console.log(post_name); console.log(post_designation); console.log(post_salary); console.log(post_date); console.log(post_img);*/ /*if(detail_info.post_title === “” || detail_info.post_description === “” || detail_info.post_designation === “” || detail_info.post_salary === “” || detail_info.post_date === “” || detail_info.post_img === “”) { alert(“Fields cannot be blank”); return; }*/ $ (“.btn btn-primary”).text(‘submitting…’); $ .ajax({ url: “/wp-admin/admin-ajax.php”, type: ‘POST’, data: { action: ‘save_post_details_form_employee’, // this is going to be used inside wordpress functions.php post_title : post_title, post_description : post_description, post_name : post_name, post_designation : post_designation, post_salary : post_salary, post_date : post_date, post_img : post_img }, success: function(data) { //alert(“Insert Success”); //console.log(data); // Show successfully for submit message $ (“.submit-message”).html(‘Thank you for submitting’); } }); }); });