Pages

Showing posts with label post. Show all posts
Showing posts with label post. Show all posts

Thursday, June 26, 2014

Fix wordpress image urls in post on migration

Whenever we migrate wordpress from old domain to new domain we seldom encounter url errors where image urls in post do not get updated etc..

To Tackle this out here is a simple sql script

 UPDATE wp_posts SET post_content = REPLACE (  
 post_content,  
 'olddomain.com/wp-content/',  
 'newdomain.com/wp-content/');  

Thursday, January 2, 2014

Wordpress-Get Post ID in functions.php

  $url = explode('?', 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);  
   $ID = url_to_postid($url[0]);  
   echo $ID;  

Saturday, December 22, 2012

Getting Tags,Categories by Post Type Wordpress/get_terms shows empty array

Recently I faced an Issue of getting tags of a Custom Postype created by Me and I solved it as follows
I registered a taxonomy for the same as follows

For Tags
register_taxonomy(ad_tag,
            array('my_cust_posttype'),
            array('hierarchical' => false,
                  'labels' => array(
                        'name' => __( 'Ad Tags', 'appthemes'),
                        'singular_name' => __( 'Ad Tag', 'appthemes'),
                        'search_items' =>  __( 'Search Ad Tags', 'appthemes'),
                        'all_items' => __( 'All Ad Tags', 'appthemes'),
                        'parent_item' => __( 'Parent Ad Tag', 'appthemes'),
                        'parent_item_colon' => __( 'Parent Ad Tag:', 'appthemes'),
                        'edit_item' => __( 'Edit Ad Tag', 'appthemes'),
                        'update_item' => __( 'Update Ad Tag', 'appthemes'),
                        'add_new_item' => __( 'Add New Ad Tag', 'appthemes'),
                        'new_item_name' => __( 'New Ad Tag Name', 'appthemes')
                    ),
                    'show_ui' => true,
                    'query_var' => true,
                    'update_count_callback' => '_update_post_term_count',
                    'rewrite' => array( 'slug' => $tag_tax_base_url, 'with_front' => false ),
            )
    );

For Categories
    register_taxonomy( APP_TAX_CAT,
            array(APP_POST_TYPE),
            array('hierarchical' => true,
                  'labels' => array(
                        'name' => __( 'Ad Categories', 'appthemes'),
                        'singular_name' => __( 'Ad Category', 'appthemes'),
                        'search_items' =>  __( 'Search Ad Categories', 'appthemes'),
                        'all_items' => __( 'All Ad Categories', 'appthemes'),
                        'parent_item' => __( 'Parent Ad Category', 'appthemes'),
                        'parent_item_colon' => __( 'Parent Ad Category:', 'appthemes'),
                        'edit_item' => __( 'Edit Ad Category', 'appthemes'),
                        'update_item' => __( 'Update Ad Category', 'appthemes'),
                        'add_new_item' => __( 'Add New Ad Category', 'appthemes'),
                        'new_item_name' => __( 'New Ad Category Name', 'appthemes')
                    ),
                    'show_ui' => true,
                    'query_var' => true,
                    'update_count_callback' => '_update_post_term_count',
                    'rewrite' => array( 'slug' => $cat_tax_base_url, 'with_front' => false, 'hierarchical' => true ),
            )
    );

And Then I retrieved Tags for my custom post type as
$mylinks_tags = get_terms('ad_tag','orderby=name&hide_empty=0');

remember the parameter hide_empty if you are starting afresh you will get an empty array if this is not set to 0 by default this is 1 which means all empty terms will be hidden.Scratched my head for a couple of hours to figure this out

Sunday, June 26, 2011

Cakephp:send multople elements values in observe field

$options=>array('url'=>array('controller'=>'admin','action'=>'update_list'),'update'=>'divIdToUpdate','frequency'=>'0.2','with'=>'Form.serialize elements($('elementid1','elementid2,elementid3')));

echo $this->Ajax->observefield('Schedulepart',$options);