WordPress.org

Ready to get started?Download WordPress

Forums

Pods - Custom Content Types and Fields
[resolved] error filtering results with relationship (4 posts)

  1. dituyi
    Member
    Posted 11 months ago #

    Hi,
    i wish you could help me with this problem. I've installed the version 2.3.4 and i'm not able to filter some results i'm getting from pods.

    This is the scenario for a discography database:
    1. Custom post type called "albumes" where i add music albums information (covers, title, tracklist and more)
    2. Second Custom post type called "canciones" where i add songs information (title, mp3 url, etc) with a relationship field with the pod "albumes".

    So, this is the code i'm using to display the songs in the details page of the album (without filtering them):
    $canciones = new Pod('canciones');
    $canciones->findRecords('orden ASC',-1);
    while ($canciones->FetchRecord()){
    //get the title
    $titulo_cancion = $canciones->get_field('name');
    //get the url
    $fichero = $canciones->get_field('fichero');
    echo $titulo_cancion; //show the song title
    }

    Ok, this is shown as expected but i need to show the songs from the actual album, not every song is in the table.
    So if i change:
    $canciones->findRecords('orden ASC',-1);
    to this:
    $canciones->findRecords('orden ASC',-1, "albumes.name = '".$titulo_album."'");
    then i recieve this error:

    Database Error; SQL: SELECT DISTINCT t.* FROM dos_posts AS t LEFT JOIN dos_postmeta AS orden ON orden.meta_key = 'orden' AND orden.post_id = t.ID WHERE ( ( albumes.name = 'Fear (LP)' ) AND ( t.post_type = "canciones" ) ) ORDER BY orden.meta_value ASC, t.menu_order, t.post_title, t.post_date; Response: Unknown column 'albumes.name' in 'where clause'.

    What am i doing wrong??
    Please, help.

    Thank you very much!

    http://wordpress.org/extend/plugins/pods/

  2. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 11 months ago #

    Instead of albumes.name, you should be using albumes.post_title

  3. dituyi
    Member
    Posted 11 months ago #

    hey Scott!
    Thanks for the fast reply. But i'm still getting an error:
    Database Error; SQL: SELECT DISTINCT t.* FROM dos_posts AS t LEFT JOIN dos_postmeta AS orden ON orden.meta_key = 'orden' AND orden.post_id = t.ID WHERE ( ( albumes.post_title = 'Fear (LP)' ) AND ( t.post_type = "canciones" ) ) ORDER BY orden.meta_value ASC, t.menu_order, t.post_title, t.post_date; Response: Unknown column 'albumes.post_title' in 'where clause'

    I don't know what's wrong.

    Thanks for your help.

  4. dituyi
    Member
    Posted 11 months ago #

    hi again,
    my bad, i have resolved the problem.

    What i was doing wrong is that the related field is called "album", not "albumes" (that's the name of the pod). I tried so many ways and i messed up. Despite this mistake, indeed you we're right and i have to use "album.post_title".

    Thank you very much for your help.

Reply

You must log in to post.

About this Plugin

About this Topic