Forum Replies Created

Viewing 15 replies - 1 through 15 (of 49 total)
  • Hi @renukadevi,

    Did you solve this? I’m having the same problem…

    Thanks in Advance!

    Thread Starter morollian

    (@morollian)

    Finally I did not use the
    “pre” tag. I just used plain “div” tags with no style, and teached the client how to edit styles using Knews built-in capabilities.

    Great Plugin! Thanks!

    Thread Starter morollian

    (@morollian)

    I solved the issue.

    I have another function that sends an email when a post is published, and it’s hooked to “publish_custom-post-name”. It looks like the headers where allready send by this function because the “publish_custom-post-type” action takes place before the “added_term_relationship” action.

    The solution is simple, I’ve written the wp_mail() function within the conditional that checks the category, so it doesn’t run when the post is “new_published” but It does when the targeted category is added.

    Here is the right code:

    function action_added_category_relationship( $object_id, $tt_id ) { 
    
        $post = get_post( $object_id );
        $ID = $post->ID;
        $category = wp_get_post_categories ($ID);
    
        if ($post->post_type == 'my_custom_post_type') {
                $author = $post->post_author; // Post author ID.
                $name = get_the_author_meta( 'display_name', $author );
                $email = get_the_author_meta( 'user_email', $author );
                $title = $post->post_title;
                $permalink = get_permalink( $ID );
                $edit = get_edit_post_link( $ID, '' );
                $to[] = sprintf( '%s <%s>', $name, $email );
                $subject = sprintf( 'Published: %s', $title );
            // Check if the category wich is been added is 8 and send the proper notification
            if (in_array('8', $category)) {
                $message = sprintf ('Hi %s! The category 8 has been added to your post “%s”.' . "\n\n", $name, $title );
                $headers[] = '';
                wp_mail( $to, $subject, $message, $headers );
            }
            // Check if the category wich is been added is 11 and send the proper notification
            if (in_array('11', $category)) {
                $message = sprintf ('Hi %s! The category 11 has been added to your post .' . "\n\n", $name, $title );
                $headers[] = '';
                wp_mail( $to, $subject, $message, $headers );
            }
    
        }
    }
    add_action ( 'added_term_relationship', 'action_added_category_relationship', 10, 2 );

    Thank’s a lot! Hope it helps someone else

    Thread Starter morollian

    (@morollian)

    Thank’s @bcworkz, but my code is’nt actually working that great…

    It works ok when adding the category, but I get a “Headers allready sent” error when I try to publish new posts… The error comes from the wp_mail line.

    It looks like the function is trigered after the publish action sends the header…

    I’m quite lost here.

    Thread Starter morollian

    (@morollian)

    Done, I used the ‘added_term_relationship’ action and it does the trick! First I get the $post object, then I can get all the data I need (author, author email, category), and send the notifications using wp_mail().

    I paste my code in case it can help someone else:

    function action_added_category_relationship( $object_id, $tt_id ) { 
    
        $post = get_post( $object_id );
        $ID = $post->ID;
        $category = wp_get_post_categories ($ID);
    
        if ($post->post_type == 'my_custom_post_type') {
                $author = $post->post_author; // Post author ID.
                $name = get_the_author_meta( 'display_name', $author );
                $email = get_the_author_meta( 'user_email', $author );
                $title = $post->post_title;
                $permalink = get_permalink( $ID );
                $edit = get_edit_post_link( $ID, '' );
                $to[] = sprintf( '%s <%s>', $name, $email );
                $subject = sprintf( 'Published: %s', $title );
            // Check if the category wich is been added is 8 and send the proper notification
            if (in_array('8', $category)) {
                $message = sprintf ('Hi %s! The category 8 has been added to your post “%s”.' . "\n\n", $name, $title );
                //$message .= sprintf( 'View: %s', $permalink );
            }
            // Check if the category wich is been added is 11 and send the proper notification
            if (in_array('11', $category)) {
                $message = sprintf ('Hi %s! The category 11 has been added to your post .' . "\n\n", $name, $title );
                //$message .= sprintf( 'View: %s', $permalink );
            }
            $headers[] = '';
            wp_mail( $to, $subject, $message, $headers );
        }
    }
    add_action ( 'added_term_relationship', 'action_added_category_relationship', 10, 2 );

    Thanks a lot @bcworkz for shedding some light here! You really helped!
    happy coding!

    Thread Starter morollian

    (@morollian)

    Thanks @bcworkz! I’ll try that… I’m not sure how I’ll get all the post info i need (author, permalink, category_name …) from the $object_ID object, but I guess I’ll find it somewhere in the codex.

    Thanks a lot!

    I looks to be solved by the last update.

    Thread Starter morollian

    (@morollian)

    I ment the htm pre tag

    I can’t not go back to 5.3, my hosting provider does not allow this change for security reasons. Let’s hope we’ll have an uptdate of this great plugin soon enough!

    Thanks hsr, I’ll try with 5,3,29 and I’ll get back to you!

    Hi @hsr!
    Which PHP Version is using your Server Now?
    Mine is running PHP 5.6.162.0

    Thanks a lot for the guidance!

    I’m having the same problem.
    I’ve tried using my old SMTP, with booth available configuratons from my hosting provider (SSL and no security), and also gmails (with SSL), and I keep getting the error:

    Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL

    Hi @advanceduser!
    Did you make this work? I’m struggling whit the same issue here…

    Tank’s Michael Simpson for a great plugin!

    morollian

    (@morollian)

    Hello Chouby, Tiago ADPS and 916VT.

    I’m facing the same trouble now.
    I love polylang, but it look like it’s not working when I try to exclude a category.

    Here is my code:

    global $wp_query;
    
     $args = array(
            'post_type' => 'post_type',
            'posts_per_page' => 20,
            'order' => 'DESC',
            'cat' => '-46'
            );
    
     $wp_query = new WP_Query($args);

    When I try to exclude the category 46, I get all the post of the post type ‘post-type’ in all languages.

    Am I doing something wrong?
    Thanks a lot!

    Thread Starter morollian

    (@morollian)

    Thanks a lot bcworkz

    I tried your solution, and it worked. The only problem is that i needed my site to show a page with the same name as the folder, not to go to the home (index.php).

    I’ve finally found a solution that seems to do the trick.
    I’m using a redirection with the [P] flag, so it’s done “behind the scenes” and does exactly what I needed. I’ve also changed the name of the page (mandatory_name) for an alias. This way my site shows the content I wanted, keeping the url I needed.

    Here’s the code if anyone needs it:

    <IfModule mod_rewrite.c>
    
    RewriteEngine on
    RewriteBase /
    RewriteRule ^mandatory_name/(.*)$ https://www.myweb.com/alias/$1 [P]
    
    </IfModule>

    Thanks for the hint bcworks!

Viewing 15 replies - 1 through 15 (of 49 total)