Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

New answers tagged

0

You can use get_term_children for checking there is have any child term or not. $taxonomy = 'custom_tax'; $term = get_queried_object(); if ( count( get_term_children( $term->term_id, $taxonomy ) ) === 0 ) { echo '<p>HTML only terms without child terms</p>'; } else { echo '<p>HTML only terms with child terms</p>'; }


2

If you add another tax_query to the args, the last tax_query will replace the previous tax_query. But anyway, if these are the criteria: When filtering by type alone, show only resources posts in that type. When filtering by subject alone, show only resources posts in that subject. When filtering by type and subject, show only resources posts which are ...


0

thanks to this page i was able to solve the same question for me. For reference, this is what i ended up with: function pluginName_myposttype_single_template($single_template) { $myposttype_template = PLUGIN_DIR . 'templates/single-myposttype.php'; return get_post_type() === 'myposttype' && file_exists($myposttype_template) ? $...


0

Just got the solution. The issue was, while clicking on search submit button I got redirected to the same post with a post_updated message what happens here is basically post_update hook fires which redirects to the same post and I can't get search query_args. What I did is, I captured the update and post save hook and added query_args and then redirected to ...


0

You access the file direct link this way: <?php echo (wpdm_get_package(get_the_ID()))['download_url']; ?>


0

finally I found the answer. function hide_edit_book_update(){ ?> <style type="text/css"> .post-php.post-type-book #publishing-action {display:none;} </style><?php } add_action( 'admin_enqueue_scripts', 'hide_edit_book_update' ); add new post and edit post we can differentiate from post-php and php-new-php css class


0

Here I've modified the code from URL you've given. function _yoursite_get_author_post_type_counts() { static $counts; if (!isset($counts)) { global $wpdb; global $wp_post_types; $sql = <<<SQL SELECT post_type, post_author, COUNT(*) AS post_count FROM {$wpdb->posts} ...


0

You can use the following code to get the post count published by a user in the author.php file $author_id = get_queried_object_id(); $getAuthorPosts = new WP_Query( array( "post_type" => "post", // Replace "post" with your custom post type. e.g. "book" OR "WHATEVER" "author" => $author_id, ) ); echo $...


0

I presume you want to remove the Publish: XXXXX from the sidebar like the images below. TO the one below without the Publish: XXXXX To do this, you would need to create a CSS File and add some code to your theme's functions.php file, or your plugin's file. The CSS File will have the following code, .edit-post-post-publish { display: none; } Name the ...


0

Have you tried a conditional if loop inside that? function deny_post_date_change( $data, $postarr ) { $your_post_type = "post"; if( $data["post_type"] == $your_post_type ) { unset( $data['post_date'] ); unset( $data['post_date_gmt'] ); return $data; } else { return $data; } } add_filter( "...


0

I found the answer : what i was doing wrong is that i have two wp_query objects with the same name ($loop). when first i made the two posts type i gave theme same name, this is why it gets confused, the solution is that never use two or more wp_query with the same name!!!


1

IFTTT works from RSS feed, simply including your post in wordpress RSS feed can do the trick... function add_cpt_to_loop_and_feed( $query ) { if ( is_home() && $query->is_main_query() || is_feed() ) $query->set( 'post_type', array( 'post', 'download' ) ); return $query; }


0

Your variables are not in functions scope. My example of function: function customPagination($paged = '', $max_page = '') { global $wp_query; $big = 999999999; if( ! $paged ) $paged = get_query_var('paged'); if( ! $max_page ) $max_page = $wp_query->max_num_pages; echo paginate_links( array( 'total' => $...


2

<?php echo substr(get_the_title(), 0,42) ;?> Notice the echo and the get_the_title() This will get you the result you're looking for. Here's an alternative to consider: I've always found character limits cause weird word breaks that users find confusing. WordPress has a function called wp_trim_words that you can use. <?php echo wp_trim_words(...


1

You will be rejected from the WordPress.org theme direcotry if you include these post types in the theme. The guidelines, which are available here, state: Non-design related functionality is not allowed. (See: Plugin territory examples) And one of the examples is: Custom Post Types and Shortcodes Regarding TGM, the guidelines have this to say: ...


1

You should be able to use roles to accomplish this. Check this tutorial here: https://3.7designs.co/blog/2014/08/restricting-access-to-custom-post-types-using-roles-in-wordpress/ I would have just put this as a comment but I guess I have to have more reputation on this site.


0

You could first add the anchor links inside the blocks with something like: <a class="block-anchor" name="topic-1" title="Topic 1"> <a class="block-anchor" name="topic-1-exerciseblock-1-1" title="Exercise 1.1"> Then create a widget with some jQuery/javascript that pulls all the anchors and lists them. Probably the easiest way to do this would ...


1

Is this a sequence mismatch between the hooks? I would argue so, yes. acf/init gets executed by class ACF's init method, all in the root file acf.php - this method is hooked to WordPress' init with a priority of 5 like so add_action( 'init', array($this, 'init'), 5 ); And you probably add your CPTs with a higher priority, this means acf/init will be ...


0

While I was typing up this question, I left it for a while, found out the problem, and decided to post the answer just in case it helped anyone else. Apparently, in WordPress's infinite wisdom, it decided to make this argument in its register_post_types function: 'publicly_queryable' When this is set to true, it causes this weird phenomenon. When it is ...


0

This is the off topic question. But the answer is yes it is possible. In IFTTT we can use the Feed applet like "Feed to Tweet". So, Just create the the Feed applet with your custom post type feed URL. WordPress generates the feed URL for each post type. You can get it as below: https://yourwebsite.com/feed/?post_type={post-type-slug} E.g. Feed URL of ...


0

Ok, the problem was, that the new shop page, which I created for WooCommerce, was not defined as the shop page int the WooCommerce settings.


0

It is possible to load custom post type content by adding the following inside render(): $args = array( 'post_type' => 'menu', // Change to desired post type 'posts_per_page' => 99 ); $query = new \WP_Query($args); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); $this->data[] = array( ...


0

I adapted the code from MZAweb and codeprokanner and added lots more consistency checking to provide strict one-to-one relationships between custom posts and custom taxonomy terms. See this answer.


0

It's difficult, but not impossible to maintain the one-to-one relationship between a taxonomy and a custom post by using many hooks. Because WordPress is designed to allow many posts to tag many terms, there are various hooks that need to be used to prevent the creation of terms without custom posts and vice versa. The code below shows the complete system, ...


0

My biggest mistake was using a taxonomy named 'type'. Yes it messed everything up since it caused many conflicts (with soft fails, no error messages). I'm doing this on my localhost but somehow some changes did not come through instantly - had to log off, close and login again to see desired results.


0

This solution seems to work so far. add_filter('screen_layout_columns', 'one_column_on_screen_options'); function one_column_on_screen_options($columns) { $columns['post'] = 1; return $columns; } // Ignore user preferences stored in DB, and serve only one column layout add_filter('get_user_option_screen_layout_post', 'one_column_layout'); ...


0

Here is my function to save attachment in a field using acf plugin. It may helps $filename = $wp_upload_dir['path'].'/'.$img; // Check the type of file. We'll use this as the 'post_mime_type'. $filetype = wp_check_filetype( basename( $filename ), null ); // Prepare an array of post data for the attachment. $attachment = array( '...


0

Thanks for the input, i solved the problem with the following workaround. strtotime($event_date)


0

In your multi-taxonomy query just change the relationship to "OR" . that should do the work.


1

category_name should take a string, not an array I believe post_type is not mentioned as an arg, and thus defaults to 'post' so try: $args = array( 'post_type' => 'any', //or use cpt slug as string, or array of strings if multiple 'category_name' => 'budget', //use 'budget,premium' if you want posts with budget OR premium, use 'budget+...


1

Just in case anyone ever stumbles across this, I found the solution. First step was to create an archive.php page In there I would access the loop. The in functions.php I have a category rewrite filter to update the category rewrite rules to use the following example url index.php?wpdmcategory=category-name&paged=2 when I hit /category-name/page/2 ...


0

Looking to the problem from a different perspective, I've reached to a different solution to it. I've created a function to check the post type instead of checking the slug of the post type. Actually I was trying to assign different CSS Class to each post type add_action( 'css_class_per_post_type', 'assign_css_class_to_each_post_type' ); // to be called in ...


1

Option 1: Enable the post type archives and use a post type archive template. Enable the archives; e.g. when registering the post type using register_post_type(): register_post_type( 'shop', [ 'has_archive' => 'shop', // the archives are accessible at example.com/shop // ... ] ); Then create a custom archive template just for that post type; i....


1

If you need to do this conversion in PHP, as part of whatever import process, then you can just convert the comma-separated values into an array with explode(), and then use update_post_meta(), which will automatically serialise the value for you: $value = 'Morning,Daytime'; $array = explode( ',', $value ); update_post_meta( $post_id, 'hours_of_operation', ...


0

You'll find details here: https://gist.github.com/lukecav/05afef12feaf980c121da9afb9291ad5 OR Another approach is https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query . Use if....else and store order data in Arr[product_id] = OrderArr Kindly accept my answer if it is of any help.


1

No, it's not safe to use the /books/ URL for both a category base and custom post type base. WordPress uses the URLs to determine what type of content to serve. If you've set up 2 different types of content at the same URL, it won't have any way to know which you're requesting, and if you end up with a book slug that's the same as a category slug, you'll ...


1

You can add anything up there with the 'in_admin_header' action. Example (pseudo code): add_action( 'in_admin_header', function() { if ( ... check $post_type, $pagenow etc, to target right page only ... ) { echo '<p>Hello editor</p>'; } } );


0

You've got the unnecessary array involved around clauses. The correct code is 'meta_query' => array( 'relation' => 'AND', 'awards_clause' => array( // clause 'key' => 'awards', 'compare' => 'EXISTS', ), 'points_clause' => array( // clause 'key' => 'points', 'compare' => '...


1

Try adding array( $this, 'myskills_html' ) to the third argument. public function skillsmetabox_init() { add_meta_box( 'myskills_meta', 'Proficiency', array( $this, 'myskills_html' ) ); } Since this is class method, it should have the $this as well. The same way you did with add_action( 'save_post', array( $this, 'save_metabox_details' )...


0

It is possible that your theme does not have a blog template. Try using a different theme to see if the issue gets fixed.


0

As none of the currently existing plugins for this purpose supports WP5, a simple (but not great) solution is to use a new metabox. In your CPT's plugin: add_meta_box('pseudosticky', 'Is sticky', 'addbox', 'YOUR CUSTOM POST TYPE SLUG HERE', 'normal', 'high'); function addbox($post, $metabox) { $entered = get_post_meta($post->ID, 'pseudosticky', true);...


0

You can add custom order fields I suppose as well. $categories = get_categories( array( 'orderby' => 'description', 'order' => 'ASC' ) );


0

You can do this with pages or posts using up to four functions, included here because that's what I've got made to copy and paste for you. To add this same thing to a taxonomy, I think you need to do this with the manage_edit-tag_columns filter and the manage_tag_custom_column action. Here's a resource I found. The following is for pages (can also be ...


0

I have this running on my sites as you describe, but I use a plugin for it called Admin Columns. I think their integration with ACF is part of the paid "pro" version, though.


2

Try with this. just change CPT with your post type. function wpcodex_add_excerpt_support_for_cpt() { add_post_type_support( 'CPT', 'custom-fields' ); } add_action( 'init', 'wpcodex_add_excerpt_support_for_cpt' );


1

Post revisions have the original post as their parent, so you can get the post type by checking the post type of the revision's parent: $revision = wp_get_post_revision( $id ); $post_type = get_post_type( $revision->post_parent );


0

get_post() and get_post_meta() should work to collect the data and array_multisort() should be able to sort it into ascending order. // Query the database to get the posts from your post types $project_args = array( 'post_type' => 'projects', "numberposts" => -1 ); $task_args = array( 'post_type' => 'tasks', "numberposts" => -1 ); ...


-1

Please Try below code to get only one custom post from each terms. replace terms ids with your term ids in $array_term = array(16,21); # pass your term IDS $array_term = array(16,21); $terms_array = array( 'taxonomy' => 'categories',// you can change it according to your taxonomy 'include' => $array_term, 'parent' =&...


0

There are some plugins for that. Like https://wordpress.org/plugins/convert-post-types/


0

You probably need to use a taxonomy query rather than the terms field (I don't see terms as a valid parameter on WordPress's WP_Query documentation page). This stackexchange question and answer should provide you with the necessary code to do what you are trying to do. If, however, the categories are not custom taxonomies (or really are just categories), ...


Top 50 recent answers are included