New answers tagged

0

add_action('admin_head-edit.php', function(){ add_filter('the_title', function( $title, $id ) { return $title . the_post_thumbnail( 'thumbnail' ); }, 100, 2); }); Will produce 2 images because there are two titles on custom posts, apparently. One that is hidden and one that isn't. Adding the image markup to the hidden element will break the ...


0

Permalink structure is a hierarchy, each level should be descendent of one another, be more specific i.e. shop.com/products/books/fiction/harry-potter where every book is a product, fiction is a genre of books and Harry Potter belongs to fiction books. So in your example product/manufacturer/brand/model every brand should belong to a single manufacturer and ...


0

I suspect the problem is not when you register the post type but when you create the menu pages. When you call add_submenu_page() make sure that the $capability argument is correct. In your case you want 'edit_posts': $capability = 'edit_posts'; add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug );


1

This example worked for me using meta_input $post_id = wp_insert_post(array ( 'post_type' => 'your_post_type', 'post_title' => $your_title, 'post_content' => $your_content, 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'meta_input' => array( '_your_custom_1' => $...


1

I want to have some specific child pages for the page "Whatever", and I want them to be available at site.url/whatever/child-page-name What I want to do is to prioritize pages during the loading process, so that if a child page of "Whatever" exists with the requested name, it should always be loaded (even if a CPT exists with said name). ...


1

I would add some hidden input field to frontend form, and check for its presence in the save_post hook. ... <input type="hidden" name="saved-on-frontend" value="1"> ... And then check for it in that hooked function: function my_save_hook() { if( isset( $_POST['saved-on-frontend'] ) ) { return; // don't do ...


0

So after 2 days of searching I found a solution. Permalink manager lite + this function and all works fine. //Rewrite rule function pm_extra_permastructure_tags($default_uri, $native_slug, $post, $slug, $native_uri) { // Do not affect native URIs if($native_uri == true || empty($post->post_type) || $post->post_type !== 'mieszkanie') { return $...


1

What is Status? If it's a taxonomy - and, by the look of it, it should be - you can exclude any given term in get_previous_post_link using the $excluded_terms parameter. If status is not a taxonomy already, you might want to rethink that for performance reasons.


1

yes, offcourse it is possible, I had made two websites for selling car pieces myself and that is very possible. anything is possible. you can create your own search results with the file search.php here are two ways of getting products info: $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'meta_key' => '...


0

This is a very old Q&A but I just resolved this by ensuring that register_post_type is invoked in a callback on action 'init', not 'admin_init'. I was thinking that since I would only want my CPT maintenance to be visible to admins that I should setup on admin_init. I believe the proper way to see this is that CPT dashboard menus are generated on 'init', ...


1

In your $args array of the taxonomy add this line: 'show_admin_column' => true, that will add it to the admin edit screen


2

That's not what the rewrite argument of register_post_type means. If you set it to false, that doesn't mean "prevent any rewriting of this post type's URL, ever." That wouldn't even be possible. It simply means not to use pretty permalinks when the post is created. You can still add rewrite rules for that post type later.


0

I solved following this answer and writing: public function query_wasb_messages_by_status( $args, $request ) { if ( ! is_null( $request->get_param( 'message_status' ) ) ) { $args['meta_query'] = array( '_wasb_message_status' => array( 'key' => '_wasb_message_status', '...


0

Try It and Good Luck $args = array( 'post_type' => 'your custom post name', 'post_status' => 'publish', 'posts_per_page' => 10, ); $arr_posts = new WP_Query( $args ); if ( $arr_posts->have_posts() ) : while ( $arr_posts->have_posts() ) : $arr_posts->the_post(); echo the_title(); endwhile;endif; wp_reset_postdata();


0

As per the reply by Haris it should be something like this: function wasb_rest_parameter($args, $request) { if( isset($request["wasb_status"]) && is_numeric($request["wasb_status"]) ) { $args['meta_key'] = 'wasb_status'; $args['meta_value'] = intval($request["wasb_status"]); } return $...


0

?php while (have_posts()) : the_post(); ?> <?php $args = array('post_type' => 'employee', 'posts_per_page' => 10); $the_query = new WP_Query($args); ?> <?php if ($the_query->have_posts()) : ?> <?php while ($the_query->have_posts()) : $the_query->the_post();?> <?php endwhile; ...


1

you can try this one function exclude_some_post_type($query) { if ( ! is_admin() && $query->is_main_query() ) { if ( $query->is_search || is_home() ) { // in search page $query->set( 'post_type', 'post' ); } } } add_action( 'pre_get_posts', 'exclude_some_post_type' ); The function that applied ...


1

You've got a number of issues with you code... if (is_array($expirationtime)) is redundant because get_post_meta will always return an array if the third parameter is false. implode($expirationtime); requires a separator, e.g. implode(' ', $expirationtime);. strtotime can fail to parse your input resulting in a false value. You will get an error when trying ...


0

If you are you using WooCommerce, you can use the "woocommerce_before_thankyou" hook to achieve this. In frontend you can create a custom AJAX action to upload all form data and append the WooCommerce product ID (use WC()->cart->add_to_cart()) and your own post type logic (maybe you can add this post as draft and store the post ID in SESSION ...


0

Try It You need is make a filter for wp_get_archives(); function custom_post_type_archive_yearly($where,$args){ $post_type = isset($args['post_type']) ? $args['post_type'] : 'post'; $where = "WHERE post_type = '$post_type' AND post_status = 'publish'"; return $where; } Call this filter Hook: add_filter( 'getarchives_where','...


0

You can add custom url structures with add_rewrite_rule for example the proposed structure in your question can be achieved with something like... add_action( 'init', function() { add_rewrite_rule( '^jobs/([^/]+)/edit/?$', 'index.php?post_type=jobs&name=$matches[1]', 'top' ); } ); So now if you visited https://example.com/jobs/job-title-example/edit/...


0

This answer inspired me to find my solution - I wanted to post it here in case it helps someone in the future: use WP_Post; use WP_REST_Request; use WP_REST_Response; class PreparePostAcfData { public function preparePostAcfData(WP_REST_Response $response, WP_Post $post, WP_REST_Request $request): WP_REST_Response { $data = $response->...


0

I've 'fixed' my problem with the code below. This is a function that checks the post-type settings. If query_var has been set to false, the view button is removed from the post-type archive in the back-end. For my use-case, this solves the problem. There are no links to the posts anymore. The reason why both post_row_actions and page_row_actions is being ...


0

create a way to check the post date, and make a if statment if( $date_of_post < '2021-10-08') { header('Location:https://google.com'); die(); }


1

CPT's don't have date archives, those are a post specific feature. Having said that, nothing prevents you building a custom bespoke date archive for a CPT. Just don't expect WordPress core to do it for you, it would be a 100% custom job, you'd have to load your own date templates, modify the query, add the rewrite rules, and construct the URLs yourself.


0

Hello, I believe that the simple and most efficient way to count posts in custom post type or in a taxonomy is: $total_posts = wp_count_posts($post_type = 'game'); //or what ever else Then to echo it as follow: <?php echo $total_posts->publish; ?> <?php echo $total_posts->draft; ?> <?php echo $total_posts->future; ?> // for ...


1

If your still having issues with this you can try the following: https://developer.wordpress.org/reference/classes/wp_query/ post__in (array) – use post ids. Specify posts to retrieve. ATTENTION If you use sticky posts, they will be included (prepended!) in the posts you retrieve whether you want it or not. To suppress this behaviour use ignore_sticky_posts. ...


0

Have you declared this parameter 'has_archive' => true in your function where you created this custom post type if not then do this first and then check, hope it's working for you,


1

I searched around the internet too for this and couldn't find anything, so to me, the most valuable part of this question is verifying that nothing better is built into Wordpress. The following is the best way I know. The main difference between this and the marked answer is that it returns real WP_Post objects, and doesn't ignore the $output parameter. ...


0

I'm not sure you'll be able to organize by category using a single query. You may need to sort by category first, then by date (or vice versa). I've taken the code from this answer and applied it to your situation, though the reverse may work better for you. // First get all the categories $categories = get_categories( array ('orderby' => 'name', 'order' =...


0

Add order asc $args = array( 'post_type' => 'nd_rst_cpt_1', //custom post type name 'orderby' => 'rand', //random order 'order' => 'ASC', 'posts_per_page' => 1, //shows only single post );


0

Yes you can have all the editor links for your products. Just run a normal query for the custom post type, in this case seems like the custom post type is "product", but you should search for the custom post type name to run the query. The query will look like this: $args = array( 'post_type' => 'product', // Put more arguments if you ...


0

To determine the $post_type easily inside a function, you need to call the global post var first, here is an example: function the_views() { global $post; if ($post->post_type == "game") { $span = '<span class="fa-gamepad">'; } else { // Regular post $span = '<span class="fa-eye">'; } }


1

Did a quick test on my local dev - https://pastebin.com/bP8byGHR - look for the comments // here. On your taxonomies I had to remove capabilities because it wasn't showing on my menu, ignore if it works for you but I don't see any use case for it. Your rewrites were the issue, you can fix the permalinks structure with post_type_link: add_filter('...


1

As Howard E said, without knowing more about what and how you want to reorder it's difficult to give you useful advice. Here's a good breakdown of the options and, here are some places to start. If you want an array of posts to order your own way, you can use the native function get_posts() in order to create an array of posts based on selected arguments. ...


Top 50 recent answers are included