Why is my insert row only inserting the final row from the loop into the database rather than just inserting one
Why is my insert row only inserting the final row from the loop into the database rather than just inserting one
Why is my insert row only inserting the final row from the loop into the database rather than just inserting one
Don’t use query_posts. As noted in the Codex: Not for Secondary Loops You should not use query_posts() to create secondary listings (for example, a list of related posts at the bottom of the page, or a list of links in a sidebar widget). You should use WP_Query instead. E.g. $args = array( ‘post_type’ => ‘topic’, … Read more
I figured it out, here is the solution for anyone else wondering how to do something like this: function force_ID($query) { global $wpdb; if (substr($_SERVER[‘REQUEST_URI’],-5) == ‘.html’) { $post_id = $wpdb->get_var($wpdb->prepare(“SELECT ID FROM $wpdb->posts WHERE post_name=%s AND post_status=”publish””,substr(basename($_SERVER[‘REQUEST_URI’]),0,-5))); if ($post_id > 0) $query->set(‘page_id’,$post_id); } } add_action(‘pre_get_posts’,’force_ID’); In examining the wp-includes/query.php file, I noticed that the … Read more
<?php if (get_the_author_meta(‘ID’) == 7) : ?> Do something for user with ID 7. <?php else : ?> Do something for anybody else. <?php endif; ?> Try this, where 7 is the ID of the user.
do you have a query pulling those related posts at the bottom? the 4 squares? it looks like you need a wp_reset_query() after those as the final square is titled “prova 3” which is the post you are showing the object data for in the sidebar.
<?php $recent_comments = get_comments( array( ‘number’ => 1, ‘status’ => ‘approve’ ) ); foreach($recent_comments as $comment) : $latest_postid_with_comment = $comment->comment_post_ID; endforeach; ?> Probably way to compress this code into something smaller. But this will work.
if you set the fields parameter to ids you will get an array of ids instead of unneeded post data ex: $ongoing_args = array( ‘post_type’ => ‘promotions’, ‘meta_key’ => ‘sp_ongoingPromotion’, ‘meta_value’ => 1, ‘fields’ => ‘ids’ ); $current_args = array( ‘post_type’ => ‘promotions’, ‘meta_key’ => ‘sp_endDate’, ‘meta_value’ => date(“Y/m/d”), ‘meta_compare’ => ‘>=’, ‘orderby’ => ‘meta_value’, … Read more
The correct way: $my_query = new WP_Query(‘posts_per_page=2′); while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php global $post; print_r($post); // <– this is your postStuff ?> <?php endwhile;?> <?php wp_reset_query(); ?> Normally, you dont’t need to globalize the post. There are helper functions that should be used instead to fetch information from the current post
You could hook into ‘attachment_fields_to_edit’ and just add a row: <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Show Attachment ID * Version: 2012.06.04 * Author: Thomas Scholz <[email protected]> * Author URI: http://toscho.de * License: MIT * License URI: http://www.opensource.org/licenses/mit-license.php */ if ( ! function_exists( ‘t5_show_attachment_id’ ) ) { add_filter( ‘attachment_fields_to_edit’, ‘t5_show_attachment_id’, … Read more
Short of building it yourself, you don’t. WordPress doesn’t have a way to get a nested array of comments like that. Instead, it gets all the comments to be displayed, then uses a class called a “walker” to display them. The Walker_Comment class is built on top of the generic Walker class. The Walker class … Read more