get custom menu items

add_filter(‘wp_nav_menu_items’, ‘wp_nav_menu_custom’, 10, 2);
function wp_nav_menu_custom($items, $args) {
if( $args->theme_location == ‘primary’ ) {

$menu_name = ‘primary’;
$locations = get_nav_menu_locations();
//echo ‘<pre/>’; print_r($locations); die;
$menu = wp_get_nav_menu_object(4, $menu_name );
$menuitems = wp_get_nav_menu_items( $menu->term_id , array( ‘order’ => ‘DESC’ ) );

foreach ( $menuitems as $item ){

$id = get_post_meta( $item->ID,’_menu_item_object_id’, true );
echo ‘<br/>’;
echo $id;
//$page = get_page( $id );
//$link = get_page_link( $id );
}

}
}

 

Using meta_query to Query Posts by Postmeta

$args = array(
	'post_type' => 'product',
	'meta_query' => array(
		array(
			'key' => 'price',
			'value' => '15.00',
			'compare' => '<',
			'type' => 'NUMERIC'
		),
		array(
			'key' => 'size',
			'value' => 'S',
			'compare' => '=',
			'type' => 'CHAR'
		),
		array(
			'key' => 'sex',
			'value' => 'men',
			'compare' => '=',
			'type' => 'NUMERIC'
		)
	)
 );
$query = new WP_Query( $args );


$args = array(
	'post_type' => 'product',
	'meta_query' => array(
		array(
			'key' => 'price',
			'value' => '15.00',
			'compare' => '<',
			'type' => 'NUMERIC'
		),
		array(
			'key' => 'size',
			'value' => 'S',
			'compare' => '=',
			'type' => 'CHAR'
		),
		array(
			'key' => 'sex',
			'value' => 'men',
			'compare' => '=',
			'type' => 'NUMERIC'
		)
	),
	'meta_key' => 'price',
	'orderby' => 'meta_value',
	'order' => 'ASC'
 );
$query = new WP_Query( $args );

multiple terms for query args

‘tax_query’ => array(
‘relation’ => ‘AND’,
array(
‘taxonomy’ => ‘shop_order_status’,
‘field’ => ‘slug’,
‘terms’ => array( ‘pending’, ‘completed’, ‘delivered’, ‘dispatched’ ),
‘include_children’ => true,
‘operator’ => ‘IN’
) )

jgz compression of js and css using .htaccess

add this code to your .htaccess file

RewriteEngine on
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.jgz -f
RewriteRule (.*)\.js$ $1\.js.jgz [L]
AddType “text/javascript” .js.jgz
AddEncoding gzip .jgz

RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.jgz -f
RewriteRule (.*)\.css$ $1\.css.jgz [L]
AddType “text/css” .css.jgz
AddEncoding gzip .jgz
Options -Indexes

Create A Loop Of Images

To create our loop of images, we first need a PHP function that can grab the first image from each post and return its URL. To do this, paste the following function in your functions.php file. Don’t forget to define a default image on line 10.

 

function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}

Once you’ve saved the functions.php file, you are now ready to display your image loop.


<?php
if (have_posts()) :
    while (have_posts()) : the_post(); ?>
        <a href="<?php the_permalink();?>" title="<?php the_title(); ?>">
        <img src="http://media.smashingmagazine.com/wp-content/uploads/images/wordpress-loop-hacks/<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>" />
        </a>
    endwhile;
endif;
?>

Use More Than One Loop On A Page, Without Printing Duplicate Posts

Let’s start with the first loop. Nothing hard here: we’re just going to get the eight most recent posts using the showposts parameter. Open the index.php file, and paste the following code to output your “featured” posts:

  1. <?php
    query_posts('showposts=8');
    $ids = array();
    while (have_posts()) : the_post();
    $ids[] = get_the_ID();
    the_title();
    the_content();
    endwhile;
    ?>

    Once that’s done, it’s time to apply our second loop and get all posts, excepted the ones we have already outputted in the first loop:

    1. <?php
      query_posts(array('post__not_in' => $ids));
      while (have_posts()) : the_post();
      the_title();
      the_content();
      endwhile;
      ?>
      
      

change wp location

UPDATE wp_options SET option_value = replace(option_value, ‘http://shell-6/iec’, ‘http://shell-14/iec’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;

UPDATE wp_posts SET guid = replace(guid, ‘http://shell-6/iec’, ‘http://shell-14/iec’);

UPDATE wp_posts SET post_content = replace(post_content, ‘http://shell-6/iec’, ‘http://shell-14/iec’);