Extract links from content

I thought regex search may become critical so html dom parser may help. See the code below (if it helps): <?php $post_content = get_the_content(); $dom = new DomDocument(); $dom->loadHTML($post_content); foreach ($dom->getElementsByTagName(‘a’) as $item) { echo “<a href=”https://wordpress.stackexchange.com/questions/315648/.$item->getAttribute(“href’).” target=”_blank” rel=””. $item->getAttribute(“rel’) .”‘>”. $item->getAttribute(‘title’) .”</a><br />”; } ?>

How to pass current loop data into nested loop

What you’ve done with the variable is correct (defining it before starting the next loop), but you’re not outputting it correctly: <p>current post = <?php $current_page; ?></p> If you want to output $current_page to the screen, you need to echo it: <p>current post = <?php echo $current_page; ?></p>

How to unserialize data from MySQL

As @Jacob said : To retrieve your option data : $your_data = get_option(‘option_tree’); To save your new data to the option : $new_data = array(…); update_option(‘option_tree’, $new_data);

How to echo every parent page title?

Check Post & Page Parameters or get_page_children(). <?php global $post; $args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => -1, ‘post_parent’ => $post->ID, ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order’ ); $parent = new WP_Query( $args ); if ( $parent->have_posts() ) : ?> <?php while ( $parent->have_posts() ) : $parent->the_post(); ?> <div id=”parent-<?php the_ID(); ?>” class=”parent-page”> <h1><a … Read more

How do I create a secondary version of the_content

You’re overcomplicating things. If you want the_content() to behave as it usually does, then don’t change it via filter or similar. Just create your new custom function, eg like so (could be placed in your functions.php or if you’re in a plugin somewhere there) function replaced_content() { $content = get_the_content(); // $content = str_replace … … Read more

proc_open() fires twice

To complete this … I initially used PHP code snippets (Insert PHP) plugin (version 2.0.6 – latest). The php page was in fact only called once, but executed twice. I didn’t have any explanation for all this described above (same temp filename, but code called twice, …). After I changed the PHP code WordPress integration … Read more

Disable if there are no children – Woocommerce

Try below code <?php $terms = get_the_terms($post->ID, ‘product_cat’); foreach ($terms as $term) { $category_name = $term->name; $parent_category_id = $term->term_id; $categories = get_categories(array(‘parent’ => $category_id)); $children = get_terms(‘product_cat’, array( ‘parent’ => $parent_category_id, ‘hide_empty’ => true )); if (!empty($children)) { echo ‘ <div class=”list-group products box”> <h4>Product Range</h4>’; foreach ($children as $subcat) { ?> <a href=”https://wordpress.stackexchange.com/questions/317473/<?php echo … Read more