• HI, I’ve been working on a wordpress theme, and I’m in a situation where I need to add a slider by name, rather than by id.

    so, putting my very basic PHP skills into the mix, I came up with this, and so far, it seems to work.

    // EXTRACT SHORTCODE ATTRIBUTES
    //extract(shortcode_atts(array(
    // ‘id’ => 0,
    //), $atts));

    extract(shortcode_atts(array(
    ‘id’ => 0,
    ‘title’ => ”,
    ), $atts));

    if($title !== ”){
    global $wpdb;
    $myposts = $wpdb->get_results( $wpdb->prepare(“SELECT * FROM $wpdb->posts WHERE post_title LIKE ‘%s'”, $wpdb->esc_like( $title ) ) );
    if(count($myposts) == 1){
    $post = get_post( $myposts[0] );
    $id = $post->ID;
    }
    }

    to use it, you can put in the shortcode
    [slide-anything title=”slider-title”]

    I’m sure that someone with better PHP skills than mine ( I’m only 3 weeks in ), can turn this into something more correct, solid and useful.

    If it’s useful enough, maybe it could make it into the next release of the code?

Viewing 1 replies (of 1 total)
  • Plugin Author simonpedge

    (@simonpedge)

    Thanks for this.
    I’ve made a note of this, and this will probably make it into a Slide Anything release at some point in the future 😉

Viewing 1 replies (of 1 total)

The topic ‘Add slider by title’ is closed to new replies.