WordPress – display relationship between blog posts and custom posts

Below is the updated code to fetch posts, please check is that helpful: $documents = get_posts(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘our_people_author’, // name of custom field ‘value’ => ‘”‘ . get_the_ID() . ‘”‘, // matches exaclty “123”, not just 123. This prevents a match for “1234” ‘compare’ … Read more

Get category name of custom post type

The following code should return you the correct category names, however I am not clear what you’re actually trying to achieve. I think you’re using the foreach loop in wrong way. Are you trying to add all the category names as css classes for the div or something else? <div class=”row masonary-wrap”> <?php $args = … Read more

How to prefix custom post type URL with custom post taxonomy term?

Ok, found the (a?) solution. “rewrite” => array( “slug” => “activity”, “with_front” => false ), and function my_injecter_agence_in_activite_url( $post_link, $id = 0 ) { $post = get_post( $id ); if ( $post->post_type == ‘activity’ || ‘publish’ == $post->post_status ) { $terms = wp_get_object_terms( $post->ID, ‘agence’ ); if ( $terms ) { $post_link = str_replace(“activity”, $terms[0]->slug.’/activite’, … Read more

Conditional editing CPT – using editor’s role and author’s usermeta

I manage to filter the posts, this seems to be enough for this project function remove_notallowed_authors( $query ) { $user = wp_get_current_user(); if ( in_array( ‘editor_group_role’, (array) $user->roles ) ) { $user_ids = get_users( [ ‘role’ => ‘user_role_that_posted’, ‘fields’ => ‘ID’ ] ); $query->set( ‘author__in’, $user_ids ); } } add_action( ‘pre_get_posts’, ‘remove_notallowed_authors’ );

In child theme, add CPT to custom taxonomy registered in parent theme

Ok, so after another hours of digging through the codex, I found a solution. Hope this helps anyone else who is runs into the same issue. I had to use the register_taxonomy_for_object_type function. And then I used the init hook. Here is the function that worked for me. function add_cpt_to_project_tax(){ register_taxonomy_for_object_type(‘project_category’, ‘external_project’); register_taxonomy_for_object_type(‘project_tag’, ‘external_project’); } … Read more