New answers tagged

0

This would be quite challenging to implement. Posts can be trashed because: They have a concept of status and corresponding field in database table WordPress code "knows" to only deal with posts of appropriate status for most purposes This solves issues of visibility (posts won't appear on front end) and interaction (trashed posts won't show up as ...


0

It will take a bit of programming on your side but you can use the delete_term_taxonomy hook to create a trash for the categories. It is run just before the category is deleted.


0

Although the hooks are passing you the ID of the changed object in the parameter $object_id, you aren't using it and are calling get_the_ID instead which will give you the ID of the current loop item. Try changing your uses of $post_id to $object_id instead.


-1

<?php if ( have_posts() ) : ?><!-- .page-header --> <div class="clearfix enclose"> <?php // Start the Loop. while ( have_posts() ) : the_post(); ?> <div class="sub-category-block"> <a href="<?php the_permalink(); ?>" title="<?php ...


0

Your code checks for child categories and shows them if they exist, but you aren't then going on to process the loop that would ordinarily display the posts in the current category. You want to extend your code to be of the form: if ( is_category() ) { $this_category = get_category($cat); if ( get_category_children( $this_category->cat_ID ) != ...


0

Posting answer found by the OP, as originally edited into the question and expanded on in comments: Here is what I ended up doing, which works a charm. I put this in my sidebar.php. Basically, it works with the custom post type name to check that it's a single post with that type. If so, I tell it to append a list of all the pages that are children of ...


3

With wp-cli installed you can run a bash script like this to remove the 'uncategorized' category from all posts with more than one category #!/bin/bash for post in $(wp post list --field=ID) do count=$(wp post term list $post 'category' --fields='name' --format="count") if [ "$count" -gt "1" ] then wp post term remove $post category '...


0

Here is what worked for me. Preethis answer almost got there, but no data was getting set. I needed to find a way of accessing the data in the array, and I used implode to do it. So here is my final code that enabled me to create a search form that loops and displays categories, allows the user to do a keyword search via any number of categories, and ...


1

let’s start by defining an HTML search form: <form method="get" action="<?php bloginfo('url'); ?>"> <fieldset> <input type="text" name="s" value="" placeholder="search&hellip;" maxlength="50" required="required" /> <p>Refine search to posts containing chosen tags:</p> <?php // generate list of categories $tags = ...


1

You're using $post->ID which is undefined. Try $_GET['post'] instead: // Get Categories if ( is_admin() && isset($_GET['post']) ) { $cats = wp_get_post_categories( (int)$_GET['post'], array( 'fields' => 'all' ) ); $cats = wp_list_pluck( $cats, 'slug' ); foreach ( $cats as $cat ) { $classes .= ' category-' . $cat; } }


0

I have flexible way where is possible to set any per_page value for each/any woprdpress site page: open functions.php of the current wp theme use smth like next: * add_filter('pre_option_posts_per_page', function($num) { if ($_SERVER['SCRIPT_URL'] == '/category/faq/') { return 999; } return $num; }); use for example http://php....


1

Assuming it is a page template that is not set to Blog Posts Page: Using pre_get_posts to show only one category doesn't work as the main query contains only page content and is not a post loop. So we can do this using a secondary query using WP_Query. Look at WP_Query category parameters <?php $args = new WP_Query( array( 'cat' => "YOUR CATEGORY ...


0

In general page URL are "last resort" match when nothing else fully matches the URL. This means that you can have something like example.com/category/cat1 be a URL of a category and example.com/category/cat1/page1 be a URL of a page. For the last to work you obviously need a grandpa page with slug "category" and a father page with slug "cat1". It is not ...


3

You can filter the posts list by appending ?category_name=xx to the admin posts list URL, and you can add a submenu page with that URL as the target via add_submenu_page: add_action( 'admin_menu', 'wpd_admin_menu_item' ); function wpd_admin_menu_item(){ add_submenu_page( 'edit.php', 'Page title', 'Menu item title', '...


0

You can loop posts by category name or ID: $query = new WP_Query( array( 'category_name' => 'staff' ) ); or $query = new WP_Query( array( 'cat' => 4 ) ); and just use good old fashion way to loop: if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); get_title(); endwhile; else : echo 'No ...


0

You have 2 ways. First is to write custom SQL query manualy for your request and loop that data. Second is to loop your data on standard way, save in multidimensional array, filter, transform and reorder that array via PHP how you need and after that loop that data and print like content. Booth ways are good but my recommendation is to write SQL query ...


0

if ( in_category('Walks and Tours') && in_category('Westminster') ) { //append whatever } You'd place that where you want the output to occur, within the Loop, of course.


0

First remove the category metabox from the post edit screen for this particular role, let's name it onecat-author: if (current_user_can('onecat-author')) { remove_meta_box ('category', 'post', 'normal'); } Next, when the post is saved use the available hook to assign the category: if (current_user_can('onecat-author')) { add_action ('save_post', ...


1

I realized that the_title(); can parse in file1.php outside of the loop, so why can't the category and ID? The following solved my issue. // file1.php <div> <h1><?php the_title(); ?></h2> <?php $category_array = wp_get_post_categories($post->ID); $category_list = array(); foreach ( $...


0

The is_category function checks the queried object. Since this is in pre_get_posts, the query has not happened yet. Check the other parameters to find if the query is going to be for cat 5, not if the results are for cat 5. Try ->get('cat').


0

If you look at the twentyfifteen theme (and the other bundled themes) you'll find code similar to the following: (this is taken from the twenty fifteen theme from inc/template-tags.php) $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); if ( $categories_list && ...


1

This sounds interesting - that's not how the front page in WordPress usually works. By default, all your latest posts will display unless you specifically set a certain page (not post) to act as your home page through Settings -> Reading. It sounds as if your theme is doing something a little bit custom. Having said that, there are still ways you can hide ...


0

EDIT: I tried the following and it works in the theme "Storefront for woocommerce"(Though it needs additional styling). For some reason though, it does not work well with the twentyfifteen theme.(The submenu does not show.) add_filter( 'wp_nav_menu_items', 'wc_products_on_nav_menu'); //filter to add the html add_action( 'save_post_product', '...


0

If you want to get product filter by category and brand (both) so you can add following code.. $args = array( 'post_type' => array('post','product'), 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'product_cat', 'terms' => 82, 'field' => 'id' ), array( ...


0

I might be completely missing what you want here, but it sounds like you're saying you want the parent category's slug to echo out, rather than the parent category's human readable name. Rather than this: echo $parent->name; You just need this instead: echo $parent->slug; You can see a list of the properties here that are returned by the ...


0

<?php $QUERY = new Wp_query(array( 'post_type' => 'post_type_here', 'category_name' => 'category_name_here', // you can use cat id ... )); $counter = 0; while( $QUERY->have_posts() ) : $QUERY->the_post(); $views = absint( getPostViews( $post->ID ) ); $counter += $views; endwhile; ...


1

Since you're using a custom taxonomy, you can't use the category argument. You can find some information about custom taxonomy retrieval in this comment in the developer documentation. According to that, I think your $categoryArgs should be: $categoryArgs = array( 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => $type, '...


0

Check here Note: The category parameter needs to be the ID of the category, and not the category name.


0

Change $myposts = get_posts( 'numberposts=6&offset=$debut') to $myposts = get_posts( 'numberposts=6&category_name=home-slider&offset=$debut') OR $myposts = get_posts( 'numberposts=6&category=1&offset=$debut') replace 1 with your category ID Hope this helps


1

As of Wordpress 4.4, the add_term_meta() and get_term_meta() functions have been added. This means that the code as provided by MxmastaMills can be updated to use a far less hacky approach. Here is my update of it. There is only one field as I wanted to add a custom title, but it'll work the same for all the fields you want to add. function ...


0

I think @Lafif Astahdziq was on the right track - I like his approach even though it is fairly static. Here is how I rewrote it: add_filter('get_the_terms', 'hide_categories_terms', 10, 3); function hide_categories_terms($terms, $post_id, $taxonomy){ // define which category IDs you want to hide $excludeIDs = array(6); // get all the terms ...


0

Try this code <div class="container"> <!-- Example row of columns --> <div class="row front-posts"> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <div class="line2"></div> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?> <!-- Start ...


0

From the WP-Admin. Click on Appearance > Menus In the top right, click "Screen Options" Select (check) "CSS Classes" Then you will have added the optional "CSS CLASSES" to each menu item.


0

No, you cannot (easily) choose what tag ID is assigned. It's not random - it's the next ID available after the last one that was created in the database. If you really want to control tag IDs, you'll need to clear your database and start fresh, and create each tag in the order you want their IDs to be (and you won't be able to change them afterwards without ...



Top 50 recent answers are included