Prevent post from being published and show error

The argument syntax in your strpos() call is such that it’s testing the content for the literal string “$words” instead of the content of the $words variable. publish_post action hooks do not directly receive a post’s content as an argument. However if you use the provided arguments as detailed by the documentation, it is not … Read more

Is there a way to define the $post var outside the loop?

I think setup_postdata($post) (internal) function does that. I failed to find proper documentation for it in Codex (typical), but there are examples with it here and there like in Displaying Posts Using a Custom Select Query. This test snippet seems to work fine for example code you have in question: foreach ( $cat1 as $post … Read more

Permalink structure and dedicated comment pages

You can change the permalink setting to /p%post_id%, but this will also set the front property of the WP_Rewrite object to /p, so some URLs will also get this in front (/pauthor for example). You can counter this by changing the $wp_rewrite->front property again: add_action( ‘permalink_structure_changed’, ‘wpse5595_rewrite_front_reset’ ); add_action( ‘init’, ‘wpse5595_rewrite_front_reset’ ); function wpse5595_rewrite_front_reset() { … Read more