• Hi,
    When I save a post the post_category number of the post in the wp_posts table is always setted on “0” zero.
    If I do a query for catch the last post of a category for example:
    (SELECT ID, post_title FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_date_gmt < ‘$today’ AND post_category IN (3, 5, 6, 7) ORDER BY post_date DESC LIMIT 0, 5″)
    this query don’t show, obviously, all the post that have post_category = 0 assigned automatically…
    Is a bug of wordpress? How can I resolve my problem?
    Sorry for my English but I am an italian user…

    Thanks in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    post_category is no longer used. Categories are now just a type of term, and the term_relationships table holds the links between the posts table and the term_taxonomy table (which defines terms as part of a taxonomy.. ‘category’ in your case).

    If you want all the posts in categories (3,5,6,7), you need to do something more like this:

    SELECT DISTINCT ID, post_title FROM $wpdb->posts as p
    INNER JOIN $wpdb->term_relationships AS tr ON
    (p.ID = tr.object_id AND
    tr.term_taxonomy_id IN (3,5,6,7) )
    INNER JOIN $wpdb->term_taxonomy AS tt ON
    (tr.term_taxonomy_id = tt.term_taxonomy_id AND
    taxonomy = 'category');
    Thread Starter japgalaxy

    (@japgalaxy)

    thanks thanks thanks thanks!!! You are my hero!!! ??

    ichamarazi

    (@ichamarazi)

    Hello Otto. I’m looking for specialist’s help. I’m sure you can help me.

    I would like to have something like this :

    <select>
    <option value=”{term_taxonomy_id}”>Category WP 1</option>
    <option value=”{term_taxonomy_id}”>Category WP 2</option>
    <option value=”{term_taxonomy_id}”>Category WP 3</option>
    <option value=”{term_taxonomy_id}”>…</option>
    </select>

    What is the MySQL Request in order to have all my categories in a select box ?

    Thank you and excuse my poor english (i’m a french guy) !

    ichamarazi

    (@ichamarazi)

    Hello Otto. I’m looking for specialist’s help. I’m sure you can help me.

    I would like to have something like this :

    <select>
    <option value="{term_taxonomy_id}">Category WP 1</option>
    <option value="{term_taxonomy_id}">Category WP 2</option>
    <option value="{term_taxonomy_id}">Category WP 3</option>
    <option value="{term_taxonomy_id}">...</option>
    </select>

    What is the MySQL Request in order to have all my categories in a select box ?

    Thank you and excuse my poor english (i’m a french guy) !

    Hello! I’ve got a related question: I’m trying to relate a query to the taxonomy table for each ID that I pull out to see if that post is in a category. Here’s my original query:

    $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date), ID
      		FROM $wpdb->posts WHERE MONTH(post_date) = $thismonth
      		AND YEAR(post_date) = $thisyear
      		AND post_status = 'publish' AND post_type='post'
      		AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
      	if ( $dayswithposts ) {
      		$counter = 0;
    		foreach ( $dayswithposts as $daywith ) {
    
      			$daywithpost[] = $daywith[0];
    
    			//echo $daywithpost[$counter]. " | ";
    			//$counter += 1;
      		}
      	} else {
      		$daywithpost = array();
      	}

    Is there anyway to:
    – Lookup the ID to the Taxonomy table
    – Check for the category name of number
    – Only put those that pass this test into the array

    -Brandon

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘post_category not assigned to posts’ is closed to new replies.