Skip to content

Instantly share code, notes, and snippets.

@atanemani
atanemani / mrj-change-terms-taxonomy-function.php
Created November 19, 2023 13:25
How to convert or change terms taxonomy?
<?php
function mrj_change_terms_taxonomy($term_id, $future_taxonomy)
{
global $wpdb;
$update = $wpdb->update(
$wpdb->prefix . 'term_taxonomy',
['taxonomy' => $future_taxonomy],
['term_taxonomy_id' => $term_id],
['%s'],
@atanemani
atanemani / how-to-convert-or-change-post-types-in-wordpress.php
Last active November 19, 2023 11:56
How to Convert or Change Post Types in WordPress
<?php
$transformable_posts = get_posts([
'post_type' => ['microcontent', 'banner'],
'post_status' => ['publish', 'draft'],
'posts_per_page' => -1
]);
if (!empty($transformable_posts)) {
foreach ($transformable_posts as $post) {
set_post_type($post->ID, 'content');
@atanemani
atanemani / mrj-post-terms.php
Created January 3, 2022 16:29
Get post terms in WordPress
<?php
/* post terms */
if (!function_exists('postTerms')) {
function postTerms($taxonomy, $single = true, $linked = false)
{
global $post;
$terms = get_the_terms($post, $taxonomy);
if ($single) {
$term = reset($terms);
@atanemani
atanemani / mrj-wp-remove-parent-category-from-url.php
Last active November 19, 2023 11:58
How to remove paretn categories slug from child-categories URL?
<?php
add_filter( 'woocommerce_taxonomy_args_product_cat', 'mrj_remove_parent_category_from_url' );
function mrj_remove_parent_category_from_url( $args ) {
$args['rewrite']['hierarchical'] = false;
return $args;
}