categories – Exclude sub-posting with pre_get_posts from the parent category's posting loop

I am trying to change how WordPress displays posts under category pages.

Ex:

  • Cat1 (contains 1 post)
  • Cat2 (contains 1 post)
    • Subcat2 (child of cat2 contains 1 post)
  • Cat3 (contains 1 post)

The cat2 page displays the cat2 post and the subcat2 post on the cat2 page. I want to hide this subcat2 post from the cat2 loop.

I managed to edit the file archive.php with this code

 array($cat)));
  }
?>

(23 is the ID of the top parent category, so it's normal for all posts to be displayed.)

However, this approach (editing archive.php) does not meet my requirements (I use element or template archives, so archive.php is ignored) and I want to use the pre_get_posts hook in functions.php

So I tried the following:

add_action( 'pre_get_posts', function( $wp_query ){
    if ( $wp_query->is_main_query() &&  $wp_query->is_category() & ! $wp_query->is_category(23)  ) {
      $cat = get_query_var('cat');
      $wp_query->set( 'category__in', ( $cat ) );
    }
});

But the query returns nothing. Can you please tell me what's wrong with my code?

Thank you very much
Akal

Ruby inheritance – child class has only parent attributes

It's my first time using Ruby subclass inheritance.
I have a parent class A with the attribute "name: string",
and a child class B <A with an attribute "bankname: string".

When I create a B instance (B.new) with the Rails console, I get an object with only the attribute "name: string" and without the attribute "bankname: string".

Is there anything else I should specify in my B definition?

Thank you very much

Access Control – Why does not Windows allow parent processes to read / write the memory of a process?

I recently learned that in Windows, one process in general may change the memory of another process as long as it runs under the same user. I tried to execute the following code with different pids:

#include 
#include 
#include 

int main()
{
    HANDLE handle = OpenProcess(PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_VM_OPERATION|PROCESS_QUERY_INFORMATION, FALSE, 1232);

    if (handle == NULL)
        std::cout << "DENIED " << GetLastError() << "n";
    else
        std::cout << "ALLOWEDn";

    return 0;
}

I've noticed that I had mostly access to processes that ran as my own user. Processes running as system or administrator have been denied access.

In contrast, I've found that you generally have to use Linux ptrace attach to another process to read from and write to its memory. By default, only parents are allowed to attach a child process.

Is there a reason why Windows does not enforce a similar restriction where only one process that spawns another has access to its memory?

PHP – Auto-Select parent category as primary

I use Yoast SEO Premium to handle the selection of primary categories. I am currently working with one listing (Listing) custom post type with a hierarchical taxonomy of Listing of the category (Listing_cat). I need the topmost parent to be automatically selected as the primary category when publishing or editing.

The code I tried is below. The parent is automatically selected as a category when the child category is selected. But I have to go a step further. I feel close, but I miss something.

/* Auto Select Listing Parent Category on Child Category Select */

add_action('save_post', 'am_assign_listing_parent_terms', 10, 2);

function am_assign_listing_parent_terms($post_id, $post){

    if($post->post_type != 'listing')
        return $post_id;

    // get all assigned terms   
    $terms = wp_get_post_terms($post_id, 'listing_cat' );
    foreach($terms as $term){
        while($term->parent != 0 && !has_term( $term->parent, 'listing_cat', $post )){
            // move upward until we get to 0 level terms
            wp_set_post_terms($post_id, array($term->parent), 'listing_cat', true);
            $term = get_term($term->parent, 'listing_cat');
            // Update Yoast SEO Post Meta with Primary Category
            update_post_meta($post_id,'_yoast_wpseo_primary_listing_cat',$term);
        }
    }
}

add_action( 'save_post', 'set_primary_on_publish', 10, 2 );
add_action( 'edit', 'set_primary_on_publish', 10, 2 );
add_action( 'wp_insert_post', 'set_primary_on_publish', 10, 2 );

I've referred to this article: Setting the Primary Category with the Yoast SEO Plug-in – but I Need the Inverse of What It Does.

Every help is appreciated.

reactjs – Update a prop in a child component after an event in the parent component?

Take 2 components:

Parent Component
Child Component

ParentComponent sets up ChildComponent in render:

render() {
    return (
        
    )
}

Then ParentComponent wants x = & # 39; default value & # 39; in & # 39; hello & # 39; change, possibly in response to an onClick event.

I think my confusion is that I know how to set up the initial variable x, but not how to change it later.

Calculation for spawnar divs at random without exceeding the parent div in Javascript?

I'm trying to come up with a computation that randomly generates the divs, but as far as I've done that, I spin the divs outside of the parent divs, time very close to each other. I want a calculation that is generated within the parent divs and with a certain distance from each other. other.

var currentTop = 0;
var LARGURA = document.getElementById("pai").offsetWidth;
var ALTURA=document.getElementById("pai").offsetHeight;
var pai=document.getElementById("pai");


 window.setInterval(function() {
  var numAleatorio = Math.floor(Math.random()*10);
     
   
   var div = document.createElement("DIV");
   div.className = "filho";
    
   pai.appendChild(div);
   eixoX = (LARGURA/ numAleatorio) + 5;
   eixoY = (ALTURA/ numAleatorio) + 5;
   
   div.style.top = eixoY + "px";
   div.style.left = eixoX + "px";
 }, 2000);
.filho {
position: absolute;
border:solid 1px black;
background:red;
width:50px;
height:50px;
}
    #pai{
position: relative;
margin: 0 auto;
border:solid 1px black;
width:300px;
height:300px;
margin: 0 auto;
}


    
    

    

php – Display specific parent and child category lists with format

I have a code that I want to display in lists.


The word "All" above shows the list of parent categories, others show the lists of the child categories. Here is the code to display the post by category above.


NOTE: The difference for other posts is in the data category.