Get Current Child Page with get_children

PHP, snippet, Wordpress, Leave a comment

There are many method to display current child page in WordPress, this function is usefull to do the same command. Just Paste this code in functions.php

function sb_child_page_menu( $current_parent ) {

// Display Subpages on the parent and list subpages of the current parent if on the child page

	if(wp_get_post_parent_id($current_parent)) {
		$parent_ID = wp_get_post_parent_id( $current_parent );
	} else {
		$parent_ID = $current_parent;
	}

// Get the Childpages / Subpages using get_children function

	$arg = array(
		'post_parent' => $parent_ID,
	);

	$childrens = get_children( $arg );

	if( !empty($childrens) ) {
		echo '<div class="sub-page">';
		foreach ( $childrens as $children ) {
			echo '<a href="'.get_permalink($children->ID).'">'.$children->post_title.'</a>';
		}
		echo '</div>';
	}
}

Call the function within the template file:

sb_child_page_menu( get_the_ID() );

more documentation about get_children.

How to Check if Meta Value Exist in WordPress Query

snippet, WordpressLeave a comment

On a loop that performs data from custom meta field, to check if the meta key has value or exist, we can use the following query:

$testimonials = array(
	'post_type' => 'projects',
	'posts_per_page' => 4,
	'meta_key' => 'testimonial',
	'meta_value' => array(''),
	'meta_compare' => 'NOT IN'
);

The above code can be used in WordPress older than 3.5 but it still usable in the latest version of WP, currently 5.1.

Another Method to Make Your Link Bold Without Shifting Another Element

CSS, snippetLeave a comment

Related to my earlier post, here’s another method you can use in your next project ;).

Featured Image as Previous Next Post Navigation in WordPress

PHP, snippet, Wordpress, , Leave a comment

Just add this code to single.php, replace or comment the default function like the_post_navigation, get_previous_post, get_next_post, etc.

$prev_post = get_previous_post();
$prev_thumbnail = get_the_post_thumbnail( $prev_post->ID, 'large');

$next_post = get_next_post();
$next_thumbnail = get_the_post_thumbnail( $next_post->ID, 'large');

$args = array(
'prev_text'  => $prev_thumbnail,
'next_text'  => $next_thumbnail
);

the_post_navigation( $args );

Easy!

Gravity Forms: Retain the Form After a Form Submitted

snippet, Wordpress, , Leave a comment

By default, if you use Gravity Forms, after you complete a form, a notification will be shown, and the form will be dismissed. Below is the script to retain the form after a form is submitted.

Just paste into functions.php and change the _id with the form ID.

add_filter( 'gform_pre_submission_filter_ID' , "show_confirmation_and_form" , 10 , 1 );
function show_confirmation_and_form($form) {
  $shortcode = '
. '" title="false" description="false"]'; if ( array_key_exists( 'confirmations' , $form ) ) { foreach ( $form[ 'confirmations' ] as $key => $confirmation ) { $form[ 'confirmations' ][ $key ][ 'message' ] .= $shortcode; } } if ( array_key_exists( 'confirmation' , $form ) ) { $form[ 'confirmation' ][ 'message' ] .= $shortcode; } return $form; }

I found this script somewhere, but I will credit the original source once I found it.