options-permalink.php not found error 404 – wordpress

If there are no issues in your .htaccess.
If you have tried everything and it is not working… try


Line 16 it will be

 function got_mod_rewrite() { to function got_mod_rewrite() {return true;

Line 42 it will be

 function got_url_rewrite() { to function got_url_rewrite() {return true;

Get product main category woocommerce wordpress

function get_product_top_level_category ( $product_id ) {
        $product_terms            =  get_the_terms ( $product_id, 'product_cat' );
        $product_category         =  $product_terms[0]->parent;
        $product_category_term    =  get_term ( $product_category, 'product_cat' );
        $product_category_parent  =  $product_category_term->parent;
        $product_top_category     =  $product_category_term->term_id;
        while ( $product_category_parent  !=  0 ) {
                $product_category_term    =  get_term ( $product_category_parent, 'product_cat' );
                $product_category_parent  =  $product_category_term->parent;
                $product_top_category     =  $product_category_term->term_id;
        return $product_top_category;

Get post ID or product ID by Meta value

1) Method One

global $wpdb;
$results = $wpdb->get_results( "select post_id, meta_key from $wpdb->postmeta where meta_value = 'this is my example value.'", ARRAY_A );

2) Method Two

$args = array(
	'post_type'		=>	'page',
	'meta_query'	=>	array(
			'value'	=>	'this is my example value.'
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) {
  while( $my_query->have_posts() ) {
    // Do your work...
  } // end while
} // end if

WordPress website too many redirects after migration

The error above occurs when website is migrated to some other server from one server

Why is this problem
1) When website was created on a server, then its home url and site url are set to previous server domain.
2) There can be some htaccess poblem too but mostly it is first one.

Solution :
1) Open you database and upate the wp_optins tabes and change the site url and home in wp_ptions table

There can be other issues like you have nt placed the website in right directory.

To check if htaccess is working , edit htaccess and just place some random string or character and then upate it.
If you Internal server error :500 , it means the htaccess is working.

You can continue debugging further.

Get product details from wordpress database and save to other database php,mysql,wordpress

$allpro = mysql_query(" SELECT wp_posts.ID,wp_posts.post_content, wp_posts.post_title, pm1.meta_value AS field1, pm2.meta_value AS field2
FROM wp_posts
LEFT JOIN wp_postmeta AS pm1 ON ( wp_posts.ID = pm1.post_id
AND pm1.meta_key = '_price' )
LEFT JOIN wp_postmeta AS pm2 ON ( wp_posts.ID = pm2.post_id
AND pm2.meta_key = '_thumbnail_id' )
WHERE wp_posts.post_type = 'product'
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC

$productall = array();
while($pr = mysql_fetch_array($allpro))

		$im = mysql_fetch_array(mysql_query("select `guid` from `wp_posts` where `ID` = '".$pr['field2']."'"));
		$productall['ID'][] = $pr['ID'];
		$productall['post_title'][] = $pr['post_title'];
		$productall['post_content'][] = $pr['post_content'];
		$productall['price'][] = $pr['field1'];
		$productall['image'][] = $im['guid'];

$totalcount = count($productall['ID']);
//connect to database you want to save products to
for($p=1;$p< $totalcount;$p++)
		$num = mysql_num_rows(mysql_query("select * from `bb_products` where `postid_in_wp` = '".$productall['ID'][$p]."'"));
				mysql_query("insert into `bb_products`(`title`,`description`,`price`,`image`,`postid_in_wp`) values('".$productall['post_title'][$p]."','".$productall['post_content'][$p]."','".$productall['price'][$p]."','".$productall['image'][$p]."','".$productall['ID'][$p]."')");