New answers tagged

0

Note that as I got the exact same issue as in your screenshot (counter of items showed items, but NO items are shown in the list/table, not even my own). Turned out that the custom theme had a hidden "feature" .. add_action( 'pre_get_posts', 'my_change_sort_order'); function my_change_sort_order($query){ if(is_archive()): ...


1

You have to register custom capabilities and then apply inside the register post type function function register_website_caps() { $admins = get_role( 'administrator' ); $admins->add_cap( 'edit_website' ); $admins->add_cap( 'read_website' ); $admins->add_cap( 'delete_website' ); $admins->add_cap( 'edit_websites' ); $...


1

If we look at the register_post_type documentation, in the rewrite option, there is a sub-option that controls this: 'with_front' => bool Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true So something like ...


1

I'm guessing it's because you used order_by when it should actually be orderby - that order_by wasn't just a typo in the question, right? And also, if the meta value is a date, then you should also set the meta_type parameter to DATE so that the sorting works as expected. So try with: $the_query = new WP_Query( array( 'post_type' => 'event', '...


0

Answering questions myself. I hope this will help some folks. 1.How to create REST API for the custom post type If you're creating a new custom post type then make sure this option is set to true in your arguments array: show_in_rest' => true, If your custom post is from a theme or plugin and you want to enable rest-api for it, then add this code into ...


1

The posts table, wp_posts is probably the most important table in the WordPress database but it does not contain only blog posts as its name implies. It stores various types of content including posts, pages, menu items, media attachments and any custom post types (CPT) that a site uses. The ID column of this table is the unique number assigned to each ...


0

Ali, as mentioned in the comments here's the method I'd use to save. As you can see, it sets out the assorted fields and then runs the save process a single time, rather than setting the logic over and over for each field. function save_book_meta_data( $post_id ) { if( !current_user_can( 'edit_post', $post_id ) ) { return $post_id; } ...


1

Your query args contains a nested array, so it won't work that way — the items like posts_per_page belongs in the main array (e.g. new WP_Query( array( 'posts_per_page' => 5 ) )). So it should be like this: Note that the 'category' => 'art' won't work. Instead, use the category_name parameter to query posts by the category slug. $query1 = new WP_Query( ...


0

First of all why do you call wp_reset_query() on each while iteration? Then we simply will create new $cats array and check if new "category" is not already there = then show and add it to the array. <ul class="filter filter-top"> <li class="active"><a href="#" data-filter="*">All</...


1

You can use the rewrite parameter to customize the taxonomy permalinks. Here's an example which links the taxonomy to the default post post type: register_taxonomy( 'video_category', 'post', [ 'public' => true, 'rewrite' => [ 'slug' => 'videos/category', ], // ... your other parameters .. ] ); Don't forget to flush the ...


1

Q1 - Is there a difference between these 2? - Post Metadata and Queried Object. Yes. And I won't go into a detailed explanation (e.g. what a post metadata is), but these should help you for what you're trying to do: Post metadata are saved in the wp_postmeta table. (Note though, the table prefix might be different in your case, but wp_ is the default.) ...


1

No there isn't, and it isn't necessary. Post type names are their own unique identifiers. The primary reason there are no numeric IDs is because post types are registered on every page load in PHP, no table exists in the database for them, which means no row IDs. So there is no use for a unique ID that the post name doesn't already accomplish. For this ...


0

So after consulting on Facebook Advanced WordPress group, the advice was to create an object with setters and getters instead of using the declaring and getting variables in the global scope as shown in the code below: class MyPlugin { public $current_post_types; public function __construct() { add_filter('init', array($this, 'get_variables')); }...


0

I've had the same issue when registering the custom post type via template code. That's why "the_permalink" and the "get_permalink" functions were also returning "null" within the post loop of the custom post type archive page. I didn't find the reason or a code wise fix but after installing the "Permalink Manager" ...


0

Testing your code I arrived finally to an answer: In the first query I didn't use any 'operator' and it works! In the second query I used the 'operator' 'IN' and 'NOT IN' and it worked! Thank you


0

Answer for the missing Layout controls in the editor, after following up on Tom J Nowell's great tip that it is a GeneratePress feature. Tom at GeneratePress helped my solve it with a filter. By default, the Layout box is only shown for those with 'edit_theme_options' capability. The filter changes it to the custom capability, 'edit_ncpages'. // Allow ...


0

Assuming you are using the standard WordPress search, you can get the searched number with get_search_query So this code will create a new draft post if no results were found for the search: $match = get_page_by_title( sanitize_title( get_search_query() ), OBJECT, ['post_type' => 'post'] ); if ( empty( $match ) ) { ...


0

Answering your second question - yes, it is possible, you can use tax_query for this, for example, this query will get all posts that has any term of 'flowers' taxonomy AND 'colors' taxonomy: $query = new WP_Query( array( 'post_type' => 'custom-post', 'posts_per_page' => 5, 'order' => 'DESC', 'tax_query' => array( '...


0

LOL-- I had to just add posts_per_page in my $terms_year query. Leaving this up in case people need it... $terms_year = array( 'post_type' => array('publications'), 'posts_per_page'=>-1, );


1

Try adding to functions.php function filter_movies( $query ) { if( !is_admin() && $query->is_main_query() && $query->get('post_type') == 'movie') { $tax_query = array( array( 'taxonomy' => 'period', 'field' => 'slug', 'terms' => 'current', ), ); $...


0

I haven't tested, but it should be as simple as: register_post_type( 'slug', array( 'has_archive' => true, 'rewrite' => array( 'slug' => 'slug', 'feeds' => false, ), );


0

Quick correction on s_ha_dum's excellent post: There was a closing bracket at the end of the $sql statement that shouldn't be there. This worked for me: function expire_posts() { global $wpdb; $daystogo = "12"; $sql = "UPDATE {$wpdb->posts} SET `post_status` = 'draft' WHERE `post_type` = 'post' AND `post_status` = 'publish' AND ...


0

Had same issue. Have spent like few hours searching for the problem and it turned out to be just a typo: instead of incorrect order_by you should use orderby - without the underscore. So, this should work: $args = array( 'post_type' => 'event', 'meta_key' => 'events_startdate', 'orderby' => 'meta_value', ); $post_query = new ...


0

If I understand correctly, all you need to do is to add the optional parameter $append as true (the default is false) wp_set_object_terms( int $object_id, string|int|array $terms, string $taxonomy, bool $append = false ) for example, in the code you posted: wp_set_object_terms( $post_ID, $uncategorized, 'category', true); that worked for me.


Top 50 recent answers are included