Custom post type redirect to 404 page in wordpress

Avinash singh | 8:17 AM

Custom post type redirect to 404 page in wordpress

Problem:

When i create my custom post type in functions.php it works for listing the records on template file but when i click the permalink it redirects me to the Page Not Found(404) page.

Solution:

Type this function before your custom post type code  flush_rewrite_rules(true); This will work

Still if you are getting problem then go through the below points:

In certain case this happens due to some existing plugin which restrict this.
 To overcome from this problem just install a plugin to create custom post type.
 and create the post with the same name which you have created in functions.php
e.g : news_article and after creating this post type via plugin, now you can delete the function from functions.php

This works for me . Try this also help you :)

How To compress all files within a directory using PHP

Avinash singh | 8:20 AM

How To compress all files within a directory using PHP



To do this create a "zipcode.php" file where you want to create the zip file

$zip = new ZipArchive();
$zip->open('example.zip',  ZipArchive::CREATE);
$srcDir = "/public_html/example/test/";
$files= scandir($srcDir);
//var_dump($files);
foreach ($files as $file) {
  $zip->addFromString(basename($file),  file_get_contents($srcDir.$file));  
}
$zip->close();

This will create a zip file with the name example.zip where the zipcode.php is placed
Example.zip contains all the file within the test directory







Add Filter after posting a comment

Avinash singh | 8:47 AM

Add Filter after posting a comment





add_filter("comment_post", "email_project_designer");


function email_project_designer(){
//  Your custom code
   wp_mail( 'abc@example.com' , 'subject','message' );
}

Send mail to the user when comment gets approved in wordpress

Avinash singh | 8:38 AM

Send mail to the user when comment gets approved in wordpress

Action hook after comment approval




function notify_approval_to_contributor ($comment_id){

$comment = get_comment($comment_id);
if ($comment->comment_approved == 1) {
$postdata = get_post($comment->comment_post_ID);
$author = get_userdata($postdata->post_author);

$user_id= $comment->user_id;
$notification_meta_for_user = get_user_meta( $user_id,'email_notification',true );

wp_mail($comment->comment_author_email,'New comment on your article "'. stripslashes($postdata->post_title),stripslashes($comment->comment_content));
   
}
}

add_action('wp_set_comment_status', 'notify_approval_to_contributor',10,1);
add_action('edit_comment', 'notify_approval_to_contributor',10,1);

How To Call Wordpress functions on core php file or a simple template file

Avinash singh | 8:29 AM

How To Call Wordpress functions on core php file or a simple template file


require_once("../../../wp-load.php");
Add this file on the top of your page the path should be correct This works fine use this.

How to use Ajax in Wordpress

Avinash singh | 12:04 PM

How to call wordpress function using Ajax

How to call wordpress function using Jquery

Simple wp ajax example

Put this code in your template file like home.php

<input type="text" id="txt"  />
    <button>GO</button>
<div id="ajax"></div>


Create a file //custom.js
jQuery("button").click( function (){
    var name=jQuery("#txt").val();                                        // get text value

    jQuery.ajax({
            url: ajaxURL.URL,
            data: 'action=demo_page&name='+name ,             //wordpress function name (demo_page)
            beforeSend: function(){ jQuery("#ajax").html('<h1>Loading  ...</h1>'); },
            success:function(msg){ jQuery("#ajax").html(msg); }
     });
});






Put this code in your //function.php
function my_scripts_method() {
    wp_enqueue_script('jquery');           
    wp_enqueue_script('custom', get_template_directory_uri().'/custom.js','jquery');
    wp_localize_script('custom', 'ajaxURL', array('URL'=>admin_url('admin-ajax.php')) );
}   

add_action('wp_enqueue_scripts', 'my_scripts_method');    // to call custom.js and admin-ajax.php

add_action("wp_ajax_demo_page", "demo_pages");                    // get called when admin logged in
add_action("wp_ajax_nopriv_demo_page", "demo_pages");        // get called for frontend users
function demo_pages()
{
   echo "Hello Mr. ".$_REQUEST['name']."Welcome <hr/>";
    die();
}

Sending HTML Email with PHP

Avinash singh | 12:40 PM

How to send email with HTML tags in PHP

$to      = 'example@example.com';
$subject = 'Testing Mail with HTML';


$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";

// The Header section define that which type of mail do you want to send i.e  Content-Type: text/html;

 $headers = "From: myself@myemail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

mail($to, $subject, $message, $headers);


How To Play and pause video in jQuery

Avinash singh | 12:16 PM
 
After clicking on close button this jquery will work

 $( "#closethis" ).click(function (){

// You can use play and pause to stop and play the video 
 
        $("video").trigger("pause");   

// used for fadeout video section slowly

        $( ".video_section" ).fadeOut(1000);
});

Responsive design - Media Query not working on iPhone?

Avinash singh | 12:09 PM
Issue:--
I have created some media queries, that working fine in a browser when resizing on a desktop. But not for i phones and Tablets gadgets 


Do you have the meta for view port in your html?

Paste this meta in your Html i.e after <Title> tag
<meta name="viewport" content="width=device-width, initial-scale=1.0;">

How to show event image in event management plugin

Avinash singh | 6:47 PM

How to show event image in event management plugin

Event image is not showing in event management plugin

show event image through php code using event management plugin


Your Solution:
suppose you want to show event image on You own posted event
Then go to plugin Events-management->templates->Tables-> events.php
add the below code where you want to show your event image

<img src="<?php echo $EM_Event->get_image_url(); ?>"  >

Avinash Kumar Singh © 2013. All Rights Reserved | Powered by-Blogger