Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //-------------------------------------------------
- define('WP_USE_THEMES', false);
- require('../wp-load.php');
- header('Content-type: text/html; charset=utf-8');
- //-------------------------------------------------
- ?>
- <style type="text/css">
- li {
- border-top: solid 3px #f80;
- }
- </style>
- <?php
- //cats_tree();
- /*get_cats4();
- get_posts4();*/
- //post_stats();
- //user_stats();
- //comm_stats();
- tests6();
- //get_posts4();
- //------------------------------------------------
- function info() {
- echo 'stylesheet_dir='.get_stylesheet_directory().'<br/>';
- echo 'stylesheet_uri='.get_stylesheet_directory_uri().'<br/>';
- echo 'template_dir='.get_template_directory().'<br/>';
- echo 'template_uri='.get_template_directory_uri().'<br/>';
- echo str_repeat('-',50).'<br/>';
- echo 'name='.get_bloginfo('name').'<br/>';
- echo 'description='.get_bloginfo('description').'<br/>';
- echo 'wpurl='.get_bloginfo('wpurl').'<br/>';
- echo 'admin_email='.get_bloginfo('admin_email').'<br/>';
- echo 'charset='.get_bloginfo('charset').'<br/>';
- echo 'version='.get_bloginfo('version').'<br/>';
- echo 'html_type='.get_bloginfo('html_type').'<br/>';
- echo 'language='.get_bloginfo('language').'<br/>';
- echo 'stylesheet_url='.get_bloginfo('stylesheet_url').'<br/>';
- echo 'stylesheet_dir='.get_bloginfo('stylesheet_directory').'<br/>';
- echo 'template_url='.get_bloginfo('template_url').'<br/>';
- echo 'template_dir='.get_bloginfo('template_directory').'<br/>';
- echo 'pingback_url='.get_bloginfo('pingback_url').'<br/>';
- echo 'atom_url='.get_bloginfo('atom_url').'<br/>';
- echo 'rdf_url='.get_bloginfo('rdf_url').'<br/>';
- echo 'rss_url='.get_bloginfo('rss_url').'<br/>';
- echo 'rss2_url='.get_bloginfo('rss2_url').'<br/>';
- echo 'comments_atom_url='.get_bloginfo('comments_atom_url').'<br/>';
- echo 'comments_rss2_url='.get_bloginfo('comments_rss2_url').'<br/>';
- }
- //------------------------------------------------
- function atts5() {
- $args = array('post_type'=>'post', 'post_status'=>'publish');
- $que = new WP_Query($args);
- while ($que->have_posts()) {
- $que->the_post();
- echo '<br/><br/>'; the_title(); echo '<br/>';
- if (has_post_thumbnail(get_the_id())) {
- draw_att(get_the_id());
- }
- }
- }
- //----------------------------------------
- function draw_att($postID)
- {
- $args = array(
- 'numberposts' => 1,
- 'order' => 'ASC',
- 'post_mime_type' => 'image',
- 'post_parent' => $postID,
- 'post_status' => null,
- 'post_type' => 'attachment',
- );
- $attachments = get_children( $args );
- if ( $attachments ) {
- foreach ( $attachments as $attachment ) {
- $image_attributes = wp_get_attachment_image_src(
- $attachment->ID, 'thumbnail' ) ?
- wp_get_attachment_image_src( $attachment->ID, 'thumbnail' ) :
- wp_get_attachment_image_src( $attachment->ID, 'full' );
- echo 'img_attrs=<pre>'.print_r($image_attributes,true).'</pre><br/>';
- echo wp_get_attachment_thumb_url( $attachment->ID ).'<br/>';
- }
- }
- }
- //------------------------------------------------
- function atts4() {
- $images =& get_children( 'post_type=attachment&post_mime_type=image' );
- if ( empty($images) ) {
- // no attachments here
- } else {
- echo '<ul>';
- foreach ( $images as $attachment_id => $attachment ) {
- //echo wp_get_attachment_image( $attachment_id, 'full' );
- echo '<li>'.wp_get_attachment_link( $attachment_id,
- 'thumbnail', true, false, get_permalink($attachment_id)).'</li>';
- }
- echo '</ul>';
- }
- }
- //-------------------------------------------------
- function tests6() {
- /*--------------------------------
- $query = new WP_Query( 'author=123' );
- $query = new WP_Query( 'author_name=rami' );
- $query = new WP_Query( 'author=2,6,17,38' );
- $query = new WP_Query( 'author=-12' );
- $query = new WP_Query( 'cat=4' );
- $query = new WP_Query( 'category_name=staff' );
- $query = new WP_Query( 'category__in=4' );
- $query = new WP_Query( 'cat=2,6,17,38' );
- $query = new WP_Query( 'category_name=staff,news' );
- $query = new WP_Query( 'cat=-12,-34,-56' );
- $query = new WP_Query( array( 'category__and' => array( 2, 6 ) ) );
- $query = new WP_Query( array( 'category__in' => array( 2, 6 ) ) );
- $query = new WP_Query( array( 'category__not_in' => array( 2, 6 ) ) );
- $query = new WP_Query( 'tag=cooking' );
- $query = new WP_Query( 'tag_id=13' );
- $query = new WP_Query( 'tag=bread,baking' );
- $query = new WP_Query( 'tag=bread+baking+recipe' );
- $query = new WP_Query( array( 'tag__and' => array( 37, 47 ) ) );
- $query = new WP_Query( array( 'tag__in' => array( 37, 47 ) ) );
- $query = new WP_Query( array( 'tag__not_in' => array( 37, 47 ) ) );
- ------------------------------
- $args = array(
- 'post_type' => 'post',
- 'people' => 'bob'
- );
- $query = new WP_Query( $args );
- ------------------------------
- $args = array(
- 'post_type' => 'post',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'people',
- 'field' => 'slug',
- 'terms' => 'bob'
- )
- )
- );
- $query = new WP_Query( $args );
- ------------------------------
- $args = array(
- 'post_type' => 'post',
- 'people' => 'bob',
- 'language' => 'english'
- );
- $query = new WP_Query( $args );
- ------------------------------
- $args = array(
- 'post_type' => 'post',
- 'tax_query' => array(
- 'relation' => 'AND',
- array(
- 'taxonomy' => 'movie_genre',
- 'field' => 'slug',
- 'terms' => array( 'action', 'comedy' )
- ),
- array(
- 'taxonomy' => 'actor',
- 'field' => 'id',
- 'terms' => array( 103, 115, 206 ),
- 'operator' => 'NOT IN'
- )
- )
- );
- $query = new WP_Query( $args );
- ------------------------------
- $args = array(
- 'post_type' => 'post',
- 'tax_query' => array(
- 'relation' => 'OR',
- array(
- 'taxonomy' => 'category',
- 'field' => 'slug',
- 'terms' => array( 'quotes' )
- ),
- array(
- 'taxonomy' => 'post_format',
- 'field' => 'slug',
- 'terms' => array( 'post-format-quote' )
- )
- )
- );
- $query = new WP_Query( $args );
- ------------------------------
- $query = new WP_Query( 's=keyword' );
- ------------------------------
- $query = new WP_Query( 'p=7' );
- $query = new WP_Query( 'page_id=7' );
- $query = new WP_Query( 'name=about-my-life' );
- $query = new WP_Query( 'pagename=contact' );
- $query = new WP_Query( 'pagename=contact_us/canada' );
- $query = new WP_Query( 'post_parent=93' );
- $query = new WP_Query( 'post_parent=0' );
- $query = new WP_Query( array( 'post_type' => 'page', 'post__in' => array( 2, 5, 12, 14, 20 ) ) );
- $query = new WP_Query( array( 'post_type' => 'post', 'post__not_in' => array( 2, 5, 12, 14, 20 ) ) );
- $query = new WP_Query( 'post_type=page' );
- $query = new WP_Query( 'post_type=any' );
- $query = new WP_Query( array( 'post_type' => array( 'post', 'page', 'movie', 'book' ) ) );
- $query = new WP_Query( 'post_status=draft' );
- $query = new WP_Query( array( 'post_status' => array( 'pending', 'draft', 'future' ) ) );
- $query = new WP_Query( array( 'post_status' => 'any', 'post_type' => 'attachment' ) );
- $query = new WP_Query( 'posts_per_page=3' );
- $query = new WP_Query( 'posts_per_page=-1' );
- $query = new WP_Query( 'nopaging=true' );
- $query = new WP_Query( 'offset=3' ) );
- $query = new WP_Query( array( 'posts_per_page' => 5, 'offset' => 3 ) );
- $query = new WP_Query( 'paged=6' );
- $query = new WP_Query( array( 'paged' => get_query_var( 'paged' ) ) );
- -------------------------------------
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
- $query = new WP_Query( array( 'paged' => $paged ) );
- -------------------------------------
- $paged = (get_query_var('page')) ? get_query_var('page') : 1;
- $query = new WP_Query( array( 'paged' => $paged ) );
- -------------------------------------
- $query = new WP_Query( array ( 'orderby' => 'title', 'order' => 'DESC' ) );
- $query = new WP_Query( array ( 'orderby' => 'rand', 'posts_per_page' => '1' ) );
- $query = new WP_Query( array( 'orderby' => 'comment_count' ) );
- $query = new WP_Query( array ( 'post_type' => 'product', 'orderby' => 'meta_value', 'meta_key' => 'price' ) );
- $query = new WP_Query( array( 'post_type' => 'page', 'orderby' => 'title menu_order', 'order' => 'ASC' ) );
- -------------------------------------
- $args = array(
- 'post_type' => 'my_custom_post_type',
- 'meta_key' => 'age',
- 'orderby' => 'meta_value_num',
- 'order' => 'ASC',
- 'meta_query' => array(
- array(
- 'key' => 'age',
- 'value' => array(3, 4),
- 'compare' => 'IN',
- )
- )
- );
- $query = new WP_Query($args);
- -------------------------------------
- $sticky = get_option( 'sticky_posts' );
- $query = new WP_Query( 'p=' . $sticky[0] );
- -------------------------------------
- $args = array(
- 'posts_per_page' => 1,
- 'post__in' => get_option( 'sticky_posts' ),
- 'ignore_sticky_posts' => 1
- );
- $query = new WP_Query( $args );
- -------------------------------------
- $sticky = get_option( 'sticky_posts' );
- $args = array(
- 'posts_per_page' => 1,
- 'post__in' => $sticky,
- 'ignore_sticky_posts' => 1
- );
- $query = new WP_Query( $args );
- if ( $sticky[0] ) {
- // insert here your stuff...
- }
- -------------------------------------
- $query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) );
- $query = new WP_Query( array( 'ignore_sticky_posts' => 1, 'posts_per_page' => 3, 'cat' => 6 );
- -------------------------------------
- $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
- $sticky = get_option( 'sticky_posts' );
- $args = array(
- 'cat' => 3,
- 'ignore_sticky_posts' => 1,
- 'post__not_in' => $sticky,
- 'paged' => $paged
- );
- $query = new WP_Query( $args );
- -------------------------------------
- $today = getdate();
- $query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"] );
- -------------------------------------
- $week = date('W');
- $year = date('Y');
- $query = new WP_Query( 'year=' . $year . '&w=' . $week );
- -------------------------------------
- $query = new WP_Query( 'monthnum=12&day=20' );
- -------------------------------------
- // Create a new filtering function that will add our where clause to the query
- function filter_where( $where = '' ) {
- // posts for March 1 to March 15, 2010
- $where .= " AND post_date >= '2010-03-01' AND post_date < '2010-03-16'";
- return $where;
- }
- add_filter( 'posts_where', 'filter_where' );
- $query = new WP_Query( $query_string );
- remove_filter( 'posts_where', 'filter_where' );
- -------------------------------------
- // Create a new filtering function that will add our where clause to the query
- function filter_where( $where = '' ) {
- // posts in the last 30 days
- $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
- return $where;
- }
- add_filter( 'posts_where', 'filter_where' );
- $query = new WP_Query( $query_string );
- remove_filter( 'posts_where', 'filter_where' );
- -------------------------------------
- // Create a new filtering function that will add our where clause to the query
- function filter_where( $where = '' ) {
- // posts 30 to 60 days old
- $where .= " AND post_date >= '" . date('Y-m-d', strtotime('-60 days')) . "'" . " AND post_date <= '" . date('Y-m-d', strtotime('-30 days')) . "'";
- return $where;
- }
- add_filter( 'posts_where', 'filter_where' );
- $query = new WP_Query( $query_string );
- remove_filter( 'posts_where', 'filter_where' );
- -------------------------------------
- $query = new WP_Query( 'meta_key=color' );
- $query = new WP_Query( 'meta_value=blue' );
- $query = new WP_Query( 'meta_value=blue&post_type=page' );
- $query = new WP_Query( array( 'meta_key' => 'color', 'meta_value' => 'blue' ) );
- $query = new WP_Query( array( 'meta_key' => 'color', 'meta_value' => 'blue', 'meta_compare' => '!=' ) );
- -------------------------------------
- $query = new WP_Query( array( 'meta_key' => 'price', 'meta_value' => '22', 'meta_compare' => '<=', 'post_type' => 'product' ) );
- -------------------------------------
- $query = new WP_Query( array ( 'meta_value' => '_wp_zero_value' ) );
- -------------------------------------
- $args = array(
- 'post_type' => 'product',
- 'meta_query' => array(
- array(
- 'key' => 'color',
- 'value' => 'blue',
- 'compare' => 'NOT LIKE'
- )
- )
- );
- $query = new WP_Query( $args );
- -------------------------------------
- $args = array(
- 'post_type' => 'product',
- 'meta_query' => array(
- array(
- 'key' => 'color',
- 'value' => 'blue',
- 'compare' => 'NOT LIKE'
- ),
- array(
- 'key' => 'price',
- 'value' => array( 20, 100 ),
- 'type' => 'numeric',
- 'compare' => 'BETWEEN'
- )
- )
- );
- $query = new WP_Query( $args );
- -------------------------------------
- $args = array(
- 'post_type' => 'product',
- 'meta_query' => array(
- 'relation' => 'OR',
- array(
- 'key' => 'color',
- 'value' => 'blue',
- 'compare' => 'NOT LIKE'
- ),
- array(
- 'key' => 'price',
- 'value' => array( 20, 100 ),
- 'type' => 'numeric',
- 'compare' => 'BETWEEN'
- )
- )
- );
- $query = new WP_Query( $args );
- -------------------------------------
- $query = new WP_Query( array( 'post_status' => array( 'publish', 'private' ), 'perm' => 'readable' ) );
- $query = new WP_Query( array( 'posts_per_page' => 50, 'cache_results' => false ) );
- $query = new WP_Query( array( 'posts_per_page' => 50, 'update_post_meta_cache' => false ) );
- $query = new WP_Query( array( 'posts_per_page' => 50, 'update_post_term_cache' => false ) );
- ----------------------------------*/
- $args = array('post_type'=>'post');
- $query = new WP_Query($args);
- while ($query->have_posts()) {
- $query->the_post();
- }
- }
- //-------------------------------------------------
- function tests5() {
- $args = array( 'post_type'=>'post', 'order'=>'DESC', 'post_per_page'=>3);
- $query = new WP_Query($args);
- echo '<ul>';
- while ($query->have_posts()) {
- echo '<li>';
- $query->the_post();
- echo 'id='; the_id(); echo '<br/>';
- echo 'permalink='; the_permalink(); echo '<br/>';
- echo 'title='; the_title(); echo '<br/>';
- echo 'date='; the_date(); echo '<br/>';
- echo 'time='; the_time(); echo '<br/>';
- echo 'category='; the_category(); echo '<br/>';
- echo 'tags='; the_tags(); echo '<br/>';
- echo 'author='; the_author(); echo '<br/>';
- echo 'author_link='; the_author_link(); echo '<br/>';
- echo 'meta='; the_meta(); echo '<br/>';
- echo 'shortlink='; the_shortlink(); echo '<br/>';
- echo 'terms='; the_terms(get_the_id(),'category'); echo '<br/>';
- echo 'taxonomies='; the_taxonomies(); echo '<br/>';
- echo '</li>';
- }
- echo '</ul>';
- }
- //-------------------------------------------------
- function tests4() {
- $posts = get_posts('numberposts=1&offset=0&orderby=title');
- echo '<ul>';
- foreach ($posts as $post) {
- echo '<li>';
- //echo '<pre>'.print_r($post,true).'</pre>';
- echo
- 'id='. $post->ID.'<br/>'.
- 'author='. $post->post_author.'<br/>'.
- 'date='. $post->post_date.'<br/>'.
- 'date_gmt='. $post->post_date_gmt.'<br/>'.
- 'content='. '<br/>'.
- 'title='. $post->post_title.'<br/>'.
- 'excerpt='. htmlentities($post->post_excerpt).'<br/>'.
- 'status='. $post->post_status.'<br/>'.
- 'comment_status='. $post->comment_status.'<br/>'.
- 'ping_status='.$post->ping_status.'<br/>'.
- 'name='.$post->post_name.'<br/>'.
- 'modified='.$post->post_modified.'<br/>'.
- 'modified_gmt='.$post->post_modified_gmt.'<br/>'.
- 'parent='.$post->post_parent.'<br/>'.
- 'guid='.$post->guid.'<br/>'.
- 'type='.$post->post_type.'<br/>'.
- 'mime_type='.$post->post_mime_type.'<br/>'.
- 'comment_count='.$post->comment_count.'<br/>';
- echo 'permalink='.get_permalink($post->ID).'<br/>';
- echo '</li>';
- }
- echo '</ul>';
- }
- //-------------------------------------------------
- function comm_stats() {
- $args = array(
- 'post_id' => $id,
- 'order'=>'DESC'
- );
- $comments = get_comments($args);
- echo '<ul>';
- foreach($comments as $c) :
- echo '<li>';
- echo 'comment_id='.$c->comment_ID.'<br/>'.
- 'comment_post_id='.$c->comment_post_ID.'<br/>'.
- 'comment_author='.$c->comment_author.'<br/>'.
- 'comment_author_email='.$c->comment_author_email.'<br/>'.
- 'comment_author_url='.$c->comment_author_url.'<br/>'.
- 'comment_author_ip='.$c->comment_author_IP.'<br/>'.
- 'comment_date='.$c->comment_date.'<br/>'.
- 'comment_date_gmt='.$c->comment_date_gmt.'<br/>'.
- 'comment_content='.$c->comment_content.'<br/>'.
- 'comment_karma='.$c->comment_karma.'<br/>'.
- 'comment_approved='.$c->comment_approved.'<br/>'.
- 'comment_agent='.$c->comment_agent.'<br/>'.
- 'comment_type='.$c->comment_type.'<br/>'.
- 'comment_parent='.$c->comment_parent.'<br/>'.
- 'user_id='.$c->user_id.'<br/>';
- echo '</li>';
- endforeach;
- echo '</ul>';
- }
- //-------------------------------------------------
- function user_stats() {
- $blogusers = get_users('orderby=nicename');
- foreach ($blogusers as $user) {
- echo '<li>' .
- $user->user_login.'<br/>'.
- $user->user_pass.'<br/>'.
- $user->user_nicename.'<br/>'.
- $user->user_email .'<br/>' .
- $user->user_url.'<br/>'.
- $user->user_registered.'<br/>'.
- $user->user_status.'<br/>'.
- $user->display_name.
- '</li>';
- }
- }
- //-------------------------------------------------
- function post_stats() {
- $args = array( 'post_type'=>'post', 'order'=>'ASC',
- 'nopaging'=>true, );
- $query = new WP_Query( $args);
- echo '<ul>';
- while ($query->have_posts()) {
- $query->the_post();
- echo '<li><table><tr><td>';
- the_shortlink('Link');
- echo '</td><td>'.
- '<a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></td>'.
- '<td>'.implode('<br/>',get_post_class()).'</td>'.
- '<td>comments='.get_comments_number().'</td>'.
- '</tr></table></li>';
- }
- echo '</ul>';
- }
- //-------------------------------------------------
- function cats_tree() {
- ?>
- <style type="text/css">
- li {
- border:none;
- }
- ul {
- width: 300px;
- margin-left: 20px;
- border: solid 1px red;
- }
- </style>
- <?php
- cats_tree_rec(0);
- }
- //-------------------------------------------------
- function cats_tree_rec($parent_id) {
- $args = array ( 'orderby'=>'name', 'order'=>'ASC',
- 'taxonomy'=>'category', 'hide_empty'=>false, 'parent'=>$parent_id);
- $cats = get_categories($args);
- if (count($cats)==0)
- return;
- echo '<ul>';
- foreach ($cats as $cat) {
- echo '<li>'. $cat->term_id.
- ' <a href="'.get_category_link($cat->term_id).'" target="_blank">'
- .$cat->name.'</a> type='.
- $cat->type.' tax='.$cat->taxonomy.' '.$cat->parent.' '.'</li>';
- cats_tree_rec($cat->term_id);
- }
- echo '</ul>';
- }
- //-------------------------------------------------
- function get_cats4() {
- $args = array ('type'=>'post', 'orderby'=>'name', 'order'=>'ASC',
- 'taxonomy'=>'category');
- $cats = get_categories($args);
- //echo '<pre>'.print_r($cats, true).'</pre>';
- echo '<ul>';
- foreach ($cats as $cat) {
- echo '<li>'. $cat->term_id. ' '.
- $cat->name. '<br/>'. $cat->slug. '<br/>'. $cat->description. '<br/>'.
- $cat->cat_name. '<br/>'.
- $cat->category_nicename.'<br/></li>';
- }
- echo '</ul>';
- }
- //-------------------------------------------------
- function get_posts4() {
- $query = new WP_Query(
- array( 'post_type'=>'post', 'order'=>'DESC')
- );
- // The Loop
- while ( $query->have_posts() ) :
- $query->the_post();
- $done = '';
- ?>
- <li data-id="<?php the_id()?>">
- <div>
- <?php htmlspecialchars(the_title())?>
- </div>
- <?php get_comms( get_the_id()); ?>
- </li>
- <?php endwhile; ?>
- <?php
- }
- //-------------------------------------------------
- function get_comms($id) {
- $args = array(
- 'number' => '200',
- 'post_id' => $id,
- 'order'=>'DESC'
- );
- $comments = get_comments($args);
- echo str_repeat('-',40).'<br/>';
- foreach($comments as $comment) :
- echo($comment->comment_author .'<br/>'. $comment->comment_author_url.
- '<br />' . $comment->comment_content).'<br/><br/>';
- endforeach;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement