Tag Info

Hot answers tagged

4

next_posts_link and previous_posts_link (plural) are for archive pagination. For single posts you want next_post_link and previous_post_link (singular).


2

You quite likely need to simply visit your permalink settings page to refresh. Goto Admin > Settings > Permalinks. Then try your URL on the front-end again.


2

You can exclude posts from archive pages with thee help of pre_get_posts action. Usually pre_get_posts is used to modify main query, so it's best solution for your problem. function my_custom_get_posts( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_archive() ) { $query->set( ...


2

You would have to do the following to save the order data into the WordPress DB, Do a WordPress AJAX sending the data that you want to be stored in it. You can do it at every re-arrange event of the elements. Handle the AJAX call in PHP and either do an update_option() or an update_user_meta() to save the data.


2

wp_update_post expects 'ID' to be a single post ID, not an array. You will need to handle each post separately. Try: $post_ids = array( 1235, 1234, 1228, 1221, 1211, 1212, 1208, 1200 ); foreach($post_ids as $post_id) { $post = array( 'ID' => $post_id, 'post_status' => 'pending' ); wp_update_post($post); }


2

Remove the ! before is_page(). The function is_page() is built into WordPress and only tests if the post being viewed is a page or not. The ! stands for "not", so if you take it out, the code will only return true on that part if it is a page.


2

You might be running up against WordPress's global $blog_id variable in test case #2. Try this: foreach($sites as $my_blog_id => $name) { switch_to_blog($my_blog_id); $sites[$my_blog_id] = get_bloginfo('name'); restore_current_blog(); }


2

Your $args array is incorrect. You used cat=-8 which is not correct here. You will have to specify/exclude category this way 'cat' => -8. So your $args array will be $args = array( 'posts_per_page' => 3, 'orderby' => DESC, 'cat' => -8 );


2

This can be done with a very short plugin. function posts_on_home_page( $posts_per_page ) { if ( is_home() ) return 5; return $posts_per_page; } add_filter( 'pre_option_posts_per_page', 'posts_on_home_page' ); This is actually pretty close to the Codex example for pre_option_(option_name).


2

First, there is no parameter named cat in get_posts. Use category instead to input comma separated category IDs or category_name to directly inserting category name. Second, in your code you have commented out the title of the post. Try this code. <?php $cat_id = get_cat_ID('category1'); $posts = get_posts( ...


1

Working off the assumption that you're already on Post One, and want to add Post Two below it, as a "Related Posts" type feature, you can use a standard WordPress function to get an array of One's tags, then do a query to grab and display posts with tags that match. //get just the IDs of Post One's tags $tag_ids = wp_get_post_tags($post->ID, ...


1

Here you are facing a problem because if this method is a AJAX request you don't have access to the ID of post unless you pass it on your JavaScript that given ID. Exemple of what I'm talking about: var args = { action: 'getcity', state: 'RJ', post_id: $('#post_id').val() }; $.post( ajaxurl, args, function( data ) { // the success of the ...


1

You can do that with two ways. 1. You can modify the WordPress main query to force WordPress to show posts older than 30 days on archive pages and on blog page, show posts before 30 days. You can limit posts with the help of date_query. Paste this function in your functions.php file. This should work. I have tested it briefly. function ...


1

Try to get the post_id from the POST values instead of the global $post. function getcity(){ global $wpdb; if($_POST['state']) { $id=$_POST['state']; $postid = $_POST['post_id']; $district = esc_html(get_post_meta($postid , 'district ', true)); $result=$wpdb->get_results("SELECT * FROM districts WHERE ...


1

category__and needs to be an array of category ID's category__and (array) - use category id. You can modify your code to look like this $query = new WP_Query( array('category__and' => array(12,32)));



Only top voted, non community-wiki answers of a minimum length are eligible