functions – Remove a category from a post when saving a new post

I’m having problems with my code. I’m trying to remove a category from a post that’s using that category and then adding that same category when saving a post.

For example, if I have a post that’s using “First post”, when saving any post that is using that category gets removed and the new post that’s being saved is added to the category “First post”.

The code I’m using adds the category when saving a post but the previous post that’s using that category doesn’t get removed.

Here’s my code:

function save_category($post_ID){
// get all posts using 'First post' category
$categories =  wp_get_object_terms( $post_ID, 'First post' );
// query to get posts using 'First post' category
if ($categories) {
    foreach ($categories as $key => $category)
    // if post is using 'First post' category then remove the category
    if ($category->name == "First post") {
        wp_remove_object_terms( $post_ID, 'First post', 'category' );
// Add 'First post' to post when saving
wp_set_post_categories( $post_ID, get_cat_ID( "First post" ) ); 
add_action('save_post', 'save_category');

adminhtml – Email template get category content tab form select drop down attribute in Magento 2.3.1

All Email template get category content tab form select drop down attribute in Magento 2.3.1


$eavSetup->addAttribute(MagentoCatalogModelCategory::ENTITY, 'form_select', (
        'type'         => 'int',
        'label'        => 'Form Select',
        'input'        => 'select',
        'sort_order'   => 130,
        'source'       => Template::class,
        'global'       => ScopedAttributeInterface::SCOPE_STORE,
        'visible'      => true,
        'required'     => false,
        'user_defined' => false,
        'default'      => '1',
        'group'        => 'Content',


<field name="form_select">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">VendorModuleModelSourceTemplate</item>
            <item name="config" xsi:type="array">
                <item name="required" xsi:type="boolean">false</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">false</item>
                <item name="sortOrder" xsi:type="number">90</item>
                <item name="dataType" xsi:type="string">string</item>
                <item name="formElement" xsi:type="string">select</item>
                <item name="label" translate="true" xsi:type="string">Form Select</item>

enter image description here

magento2 – Magento 2.4 with ElasticSearch – include category name in index?

Is there a way to get Magento 2.4 with ElasticSearch to also index the category name alongside the product? For example, I would like someone searching for “wine” to find not only products with wine in the product name, but also products that are in the “Wine” category.

Is it possible to add additional data into the search index to achieve this?

dynamic php menu with hidden sub-categories only showing when the category name is clicked

This is for a wordpress store and I want to show the categories names automatically, but with the sub-categories hidden, the code below works perfectly with the hover effect, now I wish to have the click effect instead. The $cats variable is to use the get_terms() function, but for here to work everywhere I had included a few categories, the categories only go so far as the “third generation”.

<?php $cats = array(array('first', 'sub-first', 'sub-sub-first'),
                    array('second', 'sub-second'),
                    array('third', 'sub-third', 'sub-sub-third')); ?>
<ul class="ul1"> <?php
  foreach($cats as $cat):
    if (isset($cat(0))): ?>
      <li class="li1" onclick="test()"><a href="#"><?php echo $cat(0) ?></a> <?php
        if (isset($cat(1))):?>
          <ul class="ul2">
            <li class="li2"><a href="#"><?php echo $cat(1) ?></a> <?php
              if (isset($cat(2))):?>
                <ul class="ul3">
                  <li class="li3"><a href="#"><?php echo $cat(2) ?></a> </li>
                </ul> <?php
              endif; ?>
          </ul> <?php
        endif; ?>
      </li> <?php
  endforeach; ?>

<style media="screen">
    list-style: none;
    text-decoration: none;
    border:1px solid lightgreen;
  .ul2, .ul3{
  .li1:hover .ul2{
  .ul2:hover .ul3{

for the click effect I had remove from the style the last two hover effects and add the javascript function test();

<script type="text/javascript">
    function test(){

What is happening is that I click a category and all sub-categories are showing, What I wanted is the same as the hover effect, that if I click the first category, I have only the sub-categories of that category and so on.

If someone could help me, I have been twisting my mind over this for a few days already!

navigation – Informative mobile scrolling by tag or category

A designer came to one of our iOS engineers to show us some inspirations she saw with some iOS apps where they allow users to scroll by tag or category Some examples include Snapchat where if you go to your Stories list and to the right you see a purple scrollbar, if you click anywhere it will not only jump the location but also popup what index of the scroll you’re looking at (it sorts snaps based on recency and then alphabetical contacts).

I believe there were some other iOS apps that do this i.e. Dropbox but I wasn’t entirely sure what this UX feature would be called? Scrolling with tags? Scrolling by category?

I’ll try to add a picture when I can.

Custom Post Type with Category Separate

I have create two custom post type(movie type1 , movie 2) from function.php, but when make new category, this category duplicates itself in the POSTS(Article) and other CPT(movie type1, movie2) why?

enter image description here

function custom_post_type_week() {
// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'Movie type 1', 'Post Type General Name', 'twentythirteen' ),
        'singular_name'       => _x( 'Movie type 1', 'Post Type Singular Name', 'twentythirteen' ),
        'menu_name'           => __( 'movie type 1', 'twentythirteen' ),
        'parent_item_colon'   => __( 'Parent Movie', 'twentythirteen' ),
        'all_items'           => __( 'All Movies', 'twentythirteen' ),
        'view_item'           => __( 'View Movie', 'twentythirteen' ),
        'add_new_item'        => __( 'Add New Movie', 'twentythirteen' ),
        'add_new'             => __( 'Add New', 'twentythirteen' ),
        'edit_item'           => __( 'Edit Movie', 'twentythirteen' ),
        'update_item'         => __( 'Update Movie', 'twentythirteen' ),
        'search_items'        => __( 'Search Movie', 'twentythirteen' ),
        'not_found'           => __( 'Not Found', 'twentythirteen' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),

$args = array(
    'label'               => __( 'movies', 'twentythirteen' ),
    'description'         => __( 'Movie news and reviews', 'twentythirteen' ),
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
    'hierarchical'        => true,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
    'show_in_rest'        => true,
    // This is where we add taxonomies to our CPT
    'taxonomies'          => array( 'category','post_tag' ),

register_post_type( 'movies', $args );


add_action( ‘init’, ‘custom_post_type_week’, 0 );

categories – How to show given products only using product id array from specific category page in woocommerce

I would like to show only the list of product ids in the tax query using filter woocommerce_product_query

So I need to add an additional filter along with a tax query to filter to show only products with given ids.

$tax_query() = array(‘add filter to show only specified products’)
$q->set( ‘tax_query’, $tax_query );


vlookup – Categorize text in Google Sheets based on matching partial text in the Category index

I’m looking to match, with VLOOKUP, part of the words in a column in the main sheet to an index of keywords/categories where partial words are stored for ease in another sheet.

Here’s an example worksheet:

  1. The Expenses sheet has the data as we receive it, in columns A to C.
  2. In Column D, we’d like to auto-assign a category to these expenses. If we do this with exact text in the column B, for example, BANK VISA PREAUTH PYMT, then it’s easy. The VLOOKUP formula in column D works by getting this precise reference from the ‘Categories’ tab (cell A1 is worded exactly this way). This formula works: =IFERROR(VLOOKUP(B2,Categories!A:B,2,FALSE),"")
  3. The challenge is that our expenses of a similar type won’t always follow the exact text. For example: SEND E-TFR US***ke5 and SEND E-TFR US***xja. As such, we’d like to match just the text SEND E-TFR.

This means the VLOOKUP needs to match partials in the ‘Categories’ tab first column. How does adjust the VLOOKUP formula to achieve this?

PS. My question is quite similar to this one with the vital distinction of wanting to match substrings.
Categorize cells in Google Spreadsheets

networking – Device category between router and firewall (subnetting but nothing more)

In our office building we are eight small independent offices. In the future we would like to share one internet connection. In order to make sure that we do not access the network of each others we are looking for a device which can create eight subnets / lan-segments.

Of course this task can be done with every firewall.
The problem is that we do not want to spend 2000 dollars for a device which can use our 1Gbit/s internet access. Actually we wouldn’t use 90% of the features of a firewall. Actually we just would like to have a router which creates an individual subnet for every port. Is there a special category of devices that I can look for?