$terms = get_terms('txnm_project', array('include' => $metaportfolio->peoductinclude)); foreach($terms as $term){ $in_area[] = $term->term_id; } $posts = get_posts(array( 'post_type' => 'product', 'tax_query' => array( array( 'taxonomy' => 'txnm_project', 'terms' => $page_terms['area_term'] ? $page_terms['area_term'] : $in_area, 'field' => 'id', ) ), 'numberposts' => $metaportfolio->countperpage, 'order' => $metaportfolio->sorting ? 'ASC' : 'DESC', ));
Sunday, December 1, 2013
wordpress tax_query where taxonomy
Thursday, September 5, 2013
Thursday, July 25, 2013
custom post type with category query
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'audio', 'paged' => $paged, 'posts_per_page' => 15, 'tax_query' => array( array( 'taxonomy' => 'audio_category', 'terms' => array($cat), 'field' => 'id', ) ), 'meta_query' => array( array( 'key' => 'singername', 'value' => $archivesinger, 'compare' => 'LIKE' ), array( 'key' => 'albumn', 'value' => $archivealbum, 'compare' => 'LIKE' ), ), );
Wednesday, July 24, 2013
How To Create Custom Taxonomies Fields In WordPress
<?php
add_action('category_add_form_fields','extra_category_fields');
add_action ( 'edit_category_form_fields', 'extra_category_fields');
//add extra fields to category edit form callback function
function extra_category_fields( $tag ) { $t_id = $tag->term_id;
$cat_meta = get_option( "category_$t_id");
?><tr class="form-field">
<th scope="row" valign="top"><label for="extra1"><?php _e('Category Sidebar'); ?></label></th>
<td>
<select name="Cat_meta[sidebarpage]" id="Cat_meta[sidebarpage]">
<option value=""> </option>
<option value="organization" <?php if($cat_meta['sidebarpage']=="organization") echo "selected";?>>Organization Menu </option>
<option value="culturalbuilding" <?php if($cat_meta['sidebarpage']=="culturalbuilding") echo "selected";?>>Cultural building Menu</option>
</select>
<br />
<?php //echo $cat_meta['sidebarpage'];?>
<span class="description"><?php _e('Category Sidebar design'); ?></span>
</td>
</tr>
<?php
}
add_action('create_category','save_extra_category_fileds');
add_action ( 'edited_category', 'save_extra_category_fileds');
// save extra category extra fields callback function
function save_extra_category_fileds( $term_id ) {
if ( isset( $_POST['Cat_meta'] ) ) {
$t_id = $term_id;
$cat_meta = get_option( "category_$t_id");
$cat_keys = array_keys($_POST['Cat_meta']);
foreach ($cat_keys as $key){
if (isset($_POST['Cat_meta'][$key])){
$cat_meta[$key] = $_POST['Cat_meta'][$key];
}
}
//save the option array
update_option( "category_$t_id", $cat_meta );
}
}
Monday, July 15, 2013
Add Pop-up Windows to Your WordPress
add_action('init', 'init_theme_method'); function init_theme_method() { add_thickbox(); }
<div style="text-align:center;padding:20px;"><input alt="#TB_inline?height=300&width=400&inlineId=examplePopup1" title="add a caption to title attribute / or leave blank" class="thickbox" type="button" value="Show Thickbox Example Pop-up 1" /></div>
<div id="examplePopup1" style="display:none"><h2>Example Pop-up Window 1</h2><div style="float:left;padding:10px;"><img src="http://shibashake.com/wordpress-theme/wp-content/uploads/2010/03/bio1.jpg" width="150" height = "168"/>I was born at DAZ Studio. They created me with utmost care and that is why I am the hottie that you see today. My interests include posing, trying out cute outfits, and more posing.</div>
Sunday, June 16, 2013
WordPress How-To: Force Direct Filewrites For Upgrades
define( 'FS_METHOD', 'direct' ); define( 'FS_CHMOD_DIR', 0777 ); define( 'FS_CHMOD_FILE', 0777 );
How to Update WordPress Automatically Without Using FTP
define( 'FS_METHOD', 'direct' );
Saturday, June 15, 2013
wordpress meta value search(Multisite Global Search plugin)
$termsearch = "( post_title LIKE '%%".$term."%%' OR post_content LIKE '%%".$term."%%' OR ".$wpdb->base_prefix."v_postmeta.meta_value LIKE '%%".$term."%%' ) ";
$request = $wpdb->prepare( "SELECT ".$wpdb->base_prefix."v_posts.* from ".$wpdb->base_prefix."v_posts left join ".$wpdb->users." on ".$wpdb->users.".ID=".$wpdb->base_prefix."v_posts.post_author ". " LEFT JOIN ".$wpdb->base_prefix."v_postmeta ON(".$wpdb->base_prefix."v_posts.ID = ".$wpdb->base_prefix."v_postmeta.post_id)".
Wednesday, June 12, 2013
How Can I add a WordPress menu to the content of my page?
function content_menu_shortcode($atts, $content = null) { extract(shortcode_atts(array( 'name' => null, ), $atts)); return wp_nav_menu( array( 'menu' => $name, 'echo' => false ) ); } add_shortcode('menu', 'content_menu_shortcode');[menu name="content-menu"]
Sunday, June 9, 2013
Display multiple custom field values with the same custom field type
$beedroomsbefore = get_post_meta($post->ID, 'bedroomsbefore', false); if ($beedroomsbefore) { foreach ($bedroomsbefore as $bedroomsbefore) { echo ''; } }
Wednesday, May 15, 2013
Nextgen gallery WYSIWYG description area(just gallery description not for gallery picture description)
$editor_id = "gallerydesc"; $tacontent = stripslashes($gallery->galdesc); wp_editor($tacontent,$editor_id,array("media_buttons"=>FALSE,"textarea_name"=>$editor_id,"teeny"=>true,"textarea_rows"=>4,"editor_css"=>"","quicktags"=>false,"tinymce"=>array("theme_advanced_buttons1"=>"bold, italic, underline, blockquote, separator, strikethrough, link, unlink") ));
Saturday, May 11, 2013
Saturday, May 4, 2013
Query multiple/duplicate meta_key values
SELECT $wpdb->posts. * FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = 'productcode' AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' AND $wpdb->posts.post_date < NOW( ) AND $wpdb->postmeta.meta_value = $wpdb->postmeta.meta_value GROUP BY $wpdb->postmeta.meta_value HAVING count( * ) >1 ORDER BY $wpdb->posts.post_date DESC
Saturday, April 13, 2013
Monday, February 25, 2013
Clean up your WordPress database from weird characters
Here is a query that you can run in order to clean your database from weird characters
UPDATE wp_posts SET post_content = REPLACE(post_content, '“', '“'); UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€', '”'); UPDATE wp_posts SET post_content = REPLACE(post_content, '’', '’'); UPDATE wp_posts SET post_content = REPLACE(post_content, '‘', '‘'); UPDATE wp_posts SET post_content = REPLACE(post_content, '—', '–'); UPDATE wp_posts SET post_content = REPLACE(post_content, '–', '—'); UPDATE wp_posts SET post_content = REPLACE(post_content, '•', '-'); UPDATE wp_posts SET post_content = REPLACE(post_content, '…', '…'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '“', '“'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€', '”'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '’', '’'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '‘', '‘'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '—', '–'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '–', '—'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '•', '-'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '…', '…');
Tuesday, February 19, 2013
How to remove shortcode from home but not from the entire blog
function wpc_no_shortcode_home($content) { if ( is_home() ) { $content = strip_shortcodes( $content ); } return $content; } add_filter('the_content', 'wpc_no_shortcode_home');
Sunday, January 20, 2013
How to remove the “/blog/” from your WordPress Multisite url slug
Tuesday, January 15, 2013
Enable widgets for editor role
$role_object = get_role( 'editor' );
//print_r($role_objec);
// add $cap capability to this role object
$role_object->add_cap( 'edit_theme_options' );function custom_admin_menu() {
$user = new WP_User(get_current_user_id());
if (!empty( $user->roles) && is_array($user->roles)) {
foreach ($user->roles as $role)
$role = $role;
}if($role == "editor") {
remove_submenu_page( 'themes.php', 'themes.php' );
remove_submenu_page( 'themes.php', 'nav-menus.php' );
remove_submenu_page( 'themes.php', 'theme_options' );
remove_submenu_page( 'themes.php', 'custom-header' );
}
}add_action('admin_menu', 'custom_admin_menu', 11);
Thursday, January 3, 2013
WordPress pagination without plugins
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo '<div class="page_nav">';
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => 'Prev',
'next_text' => 'Next'
));
echo '</div>';
}
Wednesday, January 2, 2013
Facebook open graph snippet to set default image
function diww_facebook_image() { echo '<meta property="fb:admins" content="ADMIN_ID" />'; echo '<meta property="og:title" content="' . get_the_title() . '" />'; echo '<meta property="og:site_name" content="' . get_bloginfo('name') . '" />'; global $post; if ( is_singular() ) { // only if a single post or page echo '<meta property="og:type" content="article" />'; echo '<meta property="og:url" content="' . get_permalink() . '" />'; if (has_post_thumbnail( $post->ID )) { // use featured image if there is one $feat_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' ); echo '<meta property="og:image" content="' . esc_attr( $feat_image[0] ) . '" />'; }else{ // use site logo in case no featured image echo '<meta property="og:image" content="http://yourdomain.com/logo.png" />'; } } if ( is_home() ) { // for homepage only echo '<meta property="og:type" content="website" />'; echo '<meta property="og:url" content="' . get_bloginfo('url') . '" />'; echo '<meta property="og:image" content="http://yourdomain.com/logo.png" />'; } } add_action( 'wp_head', 'diww_facebook_image' );