Skip to content

how can I filter some nodes? #12

@gordielachance

Description

@gordielachance

HI !
I got a little problem here. I'm parsing JSON data from Reddit (eg. https://www.reddit.com/r/Chilledout.json); and I need to setup a function that would filter the data to remove every post that does not have a media attribute.

Something that can't be changed in my code is that this function receives a phpQuery node; and should return one too.

function get_track_nodes($body_node){

    $selector = '>data >children';
    $options = array(
        'omit_xml_declaration'      => true,
        'ignore_parser_warnings'    => true,
        'convert_from_encoding'     => 'auto',
        'convert_to_encoding'       => 'UTF-8' //match WP database (or transients won't save)
    );
    $post_nodes = qp( $body_node, null, $options )->find($selector);

    foreach($post_nodes as $key=>$node) {
        /*
        here's my problem:  
        How could I detect nodes that do not have a media attribute, 
        and how could I remove them from $post_nodes ? */
    }

    return $post_nodes;
}

How could I achieve this ?
Thanks !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions