Get category ID from category slug (not working)
You can’t use get_category_by_slug() with a custom taxonomy. You need to use get_term_by(). $category = get_term_by( ‘slug’, ‘military’, ‘product_cat’ );
You can’t use get_category_by_slug() with a custom taxonomy. You need to use get_term_by(). $category = get_term_by( ‘slug’, ‘military’, ‘product_cat’ );
For category use single_cat_title function: http://codex.wordpress.org/Function_Reference/single_cat_title For tag use single_tag_title function: http://codex.wordpress.org/Function_Reference/single_tag_title For date use get_the_date function: http://codex.wordpress.org/Function_Reference/get_the_date For example if you open twentyten theme you will see following: category.php: <h1 class=”page-title”><?php printf( __( ‘Category Archives: %s’, ‘twentyten’ ), ‘<span>’ . single_cat_title( ”, false ) . ‘</span>’ ); ?></h1> date.php: <h1 class=”page-title”> <?php if ( … Read more
taken from that very same function: // prior to wordpress 4.5.0 $args = array( ‘number’ => $number, ‘orderby’ => $orderby, ‘order’ => $order, ‘hide_empty’ => $hide_empty, ‘include’ => $ids ); $product_categories = get_terms( ‘product_cat’, $args ); // since wordpress 4.5.0 $args = array( ‘taxonomy’ => “product_cat”, ‘number’ => $number, ‘orderby’ => $orderby, ‘order’ => $order, … Read more
Digging myself deeper in documentation, I got the following result. There is a way to group your custom blocks around a given category in Gutenberg, and therefore we have the method block_categories_all. So with a filter, you can extend the default categories with custom ones. Here is my example: add_filter( ‘block_categories_all’, function( $categories, $post ) … Read more
I solved this by hooking into post-new.php, and checking for a category_id request parameter. If it does not exist, I display a form with a category dropdown that submits back to this page, and then call exit() so the regular post form does not display. If it exists, I set up a hook for wp_insert_post … Read more
This answer is essentially the same as Ünsal’s, but I’d like to elaborate a bit because despite being right his answer didn’t help me (I was just trying to remember what I’d done in the past, I should have read his more carefully and I would have figured it out, but I think for others … Read more
Add the following to your theme’s functions.php: /** * Tests if any of a post’s assigned categories are descendants of target categories * * @param int|array $cats The target categories. Integer ID or array of integer IDs * @param int|object $_post The post. Omit to test the current post in the Loop or main query … Read more
In your template where you have the Featured Image displayed: <?php the_post_thumbnail( ‘thumbnail’ ); ?> you can make it conditional on whether the Featured Image is set, then have it default to whatever you want if it’s not set. One way to do this is to put all the default images in a directory and … Read more
Load the elements into a constant using a function like this: const postSelections = []; const allPosts = wp.apiFetch({path: “/wp/v2/posts”}).then(posts => { postSelections.push({label: “Select a Post”, value: 0}); $.each( posts, function( key, val ) { postSelections.push({label: val.title.rendered, value: val.id}); }); return postSelections; }); Then use postSelections as your element “options”. el( wp.components.SelectControl, { label: __(‘Select … Read more
Here is the code to get category based previous and next links on posts: <?php $post_id = $post->ID; // current post ID $cat = get_the_category(); $current_cat_id = $cat[0]->cat_ID; // current category ID $args = array( ‘category’ => $current_cat_id, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’ ); $posts = get_posts( $args ); // get IDs of posts … Read more