Wordpress Snippets

by pixeloco

HTML

//GET SPECIFIC PAGE
<?php $recent = new WP_Query("page_id=18"); while($recent->have_posts()) : $recent->the_post();?>
    <?php the_content(); ?>
    <a class="learnmore" href="<?php the_permalink() ?>" rel="bookmark">Learn More</a>
<?php endwhile; ?>


//
<?php $content = get_the_content(); echo wp_trim_words( $content , '27' ); ?>

//SHOW ACF FIELD
<?php the_field('phone'); ?>


//REMOVE DEFAULT FORM VALUES ON BLUR
jQuery(document).ready(function ($) {

    jQuery.fn.cleardefault = function() {
      return this.focus(function() {
        if( this.value == this.defaultValue ) {
          this.value = "";
        }
      }).blur(function() {
        if( !this.value.length ) {
          this.value = this.defaultValue;
        }
      });
    };
    jQuery(".gform_wrapper input[type='text'], .gform_wrapper input[type='email'], .gform_wrapper input[type='tel'], .gform_wrapper input[type='search'], .gform_wrapper input[type='url'], .gform_wrapper input[type='number'], .gform_wrapper textarea").cleardefault();

});


//LIST CHILD PAGES OF A PARENT EVEN IF NOT ON THAT PARENT
<ul>
  <?php wp_list_pages('sort_column=menu_order&title_li=&child_of=2'); ?>
</ul>

//PAGES LOOP (example loops through children of a specified parent but change $args accordingly)
<?php query_posts(array('showposts' => 20, 'post_parent' => 2, 'post_type' => 'page', 'orderby' => 'menu_order', 'order' => 'ASC')); while (have_posts()) { the_post(); ?>
<div>
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
</div>
<?php } ?>


//CALL CUSTOM POST TYPE
<?php $args = array('post_type' => 'testimonials', 'posts_per_page'=>'1', 'orderby' => 'rand'); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();?>
    <?php the_content(); ?>
<?php endwhile;?>
<?php wp_reset_query(); ?>


//ADD CUSTOM POST TYPES
add_action( 'init', 'create_post_type' );
function create_post_type() {
  register_post_type( 'team',
    array(
      'labels' => array(
        'name' => __( 'Team...