2022 Developer Survey is open! Take survey.

New answers tagged

0 votes

Looping over terms to show post type records is duplicating posts

I seem to remember adding 'relation' => 'OR', should result in a DISTINCT query. new WP_Query( array( 'post_type' => 'method', 'showposts' => 50, 'tax_query' => ...
user avatar
  • 1,115
0 votes

List all images from a single post meta value

Get images from Gallery Custom Post Meta <?php $meta = get_post_meta(get_the_ID(), 'gallery'); foreach ($meta as $m) : $img_atts = wp_get_attachment_image_src( $m, $default ); $...
user avatar
1 vote
Accepted

Assigning a category to a custom post type in Wordpress

Couple things I've spotted: Your taxonomy registration register_taxonomy( 'document-category', 'Documents' should be register_taxonomy( 'document-category', 'document' - the second parameter is the ...
user avatar
  • 34.9k
0 votes

How to make a post accessible from multiple post type slugs?

Found the way, For anyone looking for a method in the future I'll mention how I made it work. add_action( 'parse_request', function($query){ $post_type = $post_name = NULL; if (isset($query-...
user avatar
  • 1
0 votes
Accepted

How do I disable the built-in editor and automatically configure the properties of new pages?

There are a few plugins to disable Gutenberg Editor. Suppose you can use this plugin. WordPress also provides an official plugin to disable Gutenberg and continue with Classic Editor. You can try out ...
user avatar
1 vote

Create field of Custom Post Types

As you are using the classic editor, you can add new input fields to the editing view by creating custom metaboxes. This is done with add_meta_box(). Check out the code reference for further details ...
user avatar
0 votes
Accepted

date_query empty results with custom post type

Assuming that you're trying to get all posts in the first half of 2022, as opposed to the first 6 days of 2022, then you need to be clearer with your before and after dates. date_query uses strtotime ...
user avatar
  • 7,405
2 votes
Accepted

Filter post by current 2 differents users id

Based on wordpress reference for WP_QUERY you can use author__in to filter by more than one author. It uses an array of user ids. Here is your code with the needed changes: function ...
user avatar
  • 66
0 votes
Accepted

Setting Parent Page to Post

This should be in a comment, but can't format much in there. Create a relationship between your CPT and Page. For example, create a custom taxonomy for your CPT and programatically add the pages as ...
user avatar
  • 2,630
1 vote
Accepted

Insert Custom Post Types

You maybe want to add extra information fields, and settings for individual posts - single posts in CPT - Custom Post Types. Out of the box, WordPress gives us - ‘title’ ‘editor’ (content) ‘author’ ‘...
user avatar
1 vote
Accepted

How to inherit field value from parent post into in child / sub post

You can use get_post_field( 'post_parent' ) to get the parent ID of the current post. Whilst ACF is technically off-topic, FWIW you can pass the ID of a post as the second parameter to get_field. ...
user avatar
  • 34.9k
1 vote
Accepted

Very simple wordpress block to display posts from an api call

This is because when your block was rendered for save the API call had not finished. Save components do not run on the frontend. render() { return( <div> ...
user avatar
  • 51.8k
0 votes

Custom Post Type canonical link / pagination redirecting to root

Changing the method may help. There needs to be a function. <?php function wpdocs_get_paginated_links( $query ) { // When we're on page 1, 'paged' is 0, but we're counting from 1, // so we're ...
user avatar
  • 31
1 vote
Accepted

how to show records that don't have custom meta value

the most clicked item should be first and the items that haven't been clicked yet should be last, but they are not showing up at all They aren't showing up because your posts query is only selecting ...
user avatar
  • 31.5k
1 vote
Accepted

Dynamically insert code to custom post type loop

Create a variable outside the array and then pass it to the array: <?php $catfilm = get_post_meta( get_the_ID(), "mytheme_catfilm", true ); $blog = array( 'post_type' => '...
user avatar
  • 4,860
1 vote
Accepted

Custom Post Types not queried in Custom Taxonomy archives or Native archives

Tags shared by CPTs and standard posts return only the latter, and topics archives or tag archives with only CPTs assigned return empty. As for the tag archives, that's a default behavior in ...
user avatar
  • 31.5k
1 vote

How can I add a shortcode to query Custom Post Type with ACF in Wordpress?

I ultimately figured out getting a shortcode to work by reworking the code to the following: add_shortcode( 'gr_shortcode', 'gr_shortcode' ); function gr_shortcode() { $buffer = '<h3>...
user avatar
  • 119
0 votes

post_type incorrect for custom post type

Adding another possible solution for anyone else struggling with this. Removing the category of the post from the permalink - e.g. setting wordpress to use ONLY the post name - will cause this ...
user avatar
0 votes
Accepted

Admin slow on Postlist (over 30k Posts in Database)

Perhaps this filter can help you to modify the query for the specific post type and inside wp-admin as per the documentation, this filter is called before the query is executed so you can modify/...
user avatar
  • 488
0 votes

Custom post type category link redirecting to 404 page

Its because you are already registered the cpt as blog and set has_archive to true. That means, the url https://example.co/blog/ will act as the archive page for that CPT and URLs like this (https://...
user avatar
  • 2,630
1 vote
Accepted

Parent field missing from custom post type in the block editor

tl;dr - The Parent select menu will not render in the block editor if the parent_item_colon label is an empty string. Ruling Out Common Issues First, I needed to confirm that the following frequent ...
user avatar
  • 9,927

Top 50 recent answers are included