Forum Replies Created

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter NathanielFisher

    (@nathanielfisher)

    The first method doesn’t make any difference: queries without a single quote still work and those with it still don’t. I’ve also tried a number of ways of stripping the single quote from the search query and the data it is searching. But none of them work. For example:

    global $wpdb;
    $itemName = str_replace("'", "", get_the_title( $ID ));
    
    $results = $wpdb->get_results("SELECT ID FROM $wpdb->posts where $wpdb->prepare($wpdb->posts.post_title) LIKE '$itemName' AND $wpdb->posts.post_status = 'publish' ORDER BY post_title ASC", OBJECT);

    But none of them work. I’ve also tried using str_replace within the SQL query but run into problems because of using the single quote within the query.

    Thread Starter NathanielFisher

    (@nathanielfisher)

    Is there any way to stop it? It doesn’t seem like a very useful feature, and it doesn’t do it if I upload the image via ‘set featured image’.

    Thread Starter NathanielFisher

    (@nathanielfisher)

    I was looking for a way for it to be done automatically in the same way that it does when duplicate posts have the same name.

    I’m actually trying to add the $post_id to the start of all post_names (partly so I can remove the suffix at the end). So far I’ve got it working on ones where the post_name is a duplicate, but I need it for new posts, too.

    So instead of

    www.mysite/another-post
    www.mysite/another-post-2

    it will show

    www.mysite/118-another-post
    www.mysite/119-another-post
    www.mysite/120-a-different-post
    www.mysite/121-you-get-the-point

    Anyone know how to do this?

    Thread Starter NathanielFisher

    (@nathanielfisher)

    Solution: This turned out to be due to the Bitnami WordPress installation I was using. Some kind of conflict in the .htaccess files, maybe. So I uninstalled it and reinstalled a standard WP installation using the file on the WP site, and I’m able to make changes by editing .htaccess in the wordpress install directory.

    Are you saying you’re unable to access www.cross-terrain.com/wp-admin or is it that your login information is incorrect?

    Thread Starter NathanielFisher

    (@nathanielfisher)

    I did this by going to \wordpress\htdocs\wp-includes\post.php

    There I found 3 lines that contained the code

    truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$slug"
    and for each of those three lines I removed

    . "-$slug"

    from the end, and added

    "$post_ID" . "_" .

    to the beginning, to give

    "$post_ID" . "_" . _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) )

    This seems to have replaced the -2, -3 at the end with the individual post_id at the beginning, e.g. “mysite.com/wordpress/215_anypost” which is more suitable for what I’m using it for. Also, this is done automatically and I think it will be easier to remove this prfix with a url rewrite to provide the cleaner urls I need.

    I’m not actually sure what the truncate function or strlen are there for, so if anyone else uses this, do so with caution.

    Thread Starter NathanielFisher

    (@nathanielfisher)

    Thanks. That’s what I ended up doing. Here it is, if it’s any use to anyone.

    $args = array(
        'post_type' => 'post',
    	'orderby' => 'meta_value',
    	'meta_key' => 'delivery_date',
    	'order' => 'ASC',
        'meta_query' => array(
           'relation' => 'AND',
    		 array(
                  'key' => 'supplier',
                  'value' => 'test',
                  'compare' => '='
                  ),
             array(
                'key' => 'delivery_date',
                'value' => '2015/06/27',
                'compare' => '='
                 ),
    
        )
    );
    
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) :
        while ($query->have_posts()) : $query->the_post();
    
                 echo $post_id = get_the_ID();
    			 echo "---";
    			 echo $post_title = get_the_title();
    			 echo "---";
    			 echo "<br />";
    
        endwhile;
    endif;
    Thread Starter NathanielFisher

    (@nathanielfisher)

    Thread Starter NathanielFisher

    (@nathanielfisher)

    Thanks. I did it that way because I’m still getting to grips with SQL and PHP and it seemed more straightforward that way. I just got it working by removing the reference to $wpdb->posts, as I wasn’t using that table anyway. I think the issue might have had something to do with (not properly) traversing the array. Not sure though.

    Anyway, this worked.

    <?php
    global $wpdb;
    $results =$wpdb->get_results("SELECT post_id FROM $wpdb->postmeta where  $wpdb->postmeta.meta_value = '2015/06/03' AND meta_key='mymvkey'", OBJECT);
    
    foreach ($results as $result){
    printf ($result->post_id);
    }
    ?>

    Most people seem to suggest using get_posts for stuff like this. So now I’ve got it working I’ll use your example to help me make sense of that. Thanks again.

    Thread Starter NathanielFisher

    (@nathanielfisher)

    Ok. Thanks again, Charlie.

    Thread Starter NathanielFisher

    (@nathanielfisher)

    I thought it was just a problem with my installation. Isn’t it already available through the dashboard in Taxonomies > General > Enable Categories?

    Thread Starter NathanielFisher

    (@nathanielfisher)

    Thanks for your help. I think it’s within the loop. I was editing the template and adding it to single.php, above where it says end of loop. It didn’t work for me though, but there’s a very distinct possibility it was something that I did wrong.

    Here’s how I got it working in the end.

    <?php
    $result =$wpdb->get_results("SELECT meta_value FROM $wpdb->posts , $wpdb->postmeta where  $wpdb->postmeta.post_id = $post->ID
    
    AND meta_key='TYPE_META_KEY'", OBJECT);
    
    print_r($result[0]->meta_value);
    ?>
    Thread Starter NathanielFisher

    (@nathanielfisher)

    Great. I’m not sure what happened with that code I pasted, but it’s working with yours. Thanks again, Charlie.

    Thread Starter NathanielFisher

    (@nathanielfisher)

    Turns out my syntax was off for the php in the meta tags. So I’ve managed to do it using shortcodes, e.g.

    <?php echo apply_filters( 'wpmoly_movie_date', wpmoly_get_movie_meta(null, 'release_date',) ); ?>

    The problem I’ve got now is that this returns the date in the format YYYY-MM-DD. Is there a simple way to get it as, say 1st January 2010?

    Thread Starter NathanielFisher

    (@nathanielfisher)

    Awesome. I see where I went wrong now. Thanks a lot.

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