Exclude record from findRecords

0

I've seen a lot of posts that allow you to use findRecords to display one record.

Well, I want to do that in reverse.

I have a pod with a list of categories and their links. Works great but now I've created a category I don't want people to see in the list. So it's kind of silly to list all of the categories in my PHP. Especially if I delete and/or add categories in the future. So what would the PHP code be to exclude a record from my list of records? Some kind of where statement?

asked Feb 16 '11 at 4:17

databell

56

add comment
enter at least 15 characters

10 Answers

0

So I had a similar need for this functionality that I'll share.

$project2->findRecords('rand()', 4, 'project_type.name = "' . $thecatsa . '" && t.slug != "' . $project_slug . '"');

I was developing a single page for an individual portfolio piece and I wanted to include some functionality to show other Related portfolio projects that were in the same category. However, I did not want the main portfolio project to be shown again in the "Related Projects" section.

I had set the variable $thecatsa to be equal to the project category name, so the query would pull posts from the same category as the portfolio project, but would exclude any post with the same unique slug as the main portfolio project. Boom!

Thanks again to the Pods CMS crew for making such a great and extensible mega-plugin for Wordpress. Keep up the great work!

answered Apr 7 '11 at 1:02

mjslawson

16

add comment
enter at least 15 characters
1

$where = "category != 'category_name' ";

answered Feb 16 '11 at 1:44

Rhys L. Bartels-Waller

35

add comment
enter at least 15 characters
1

How about this?

$where = ' t.slug != "basic-recipes"'; $categories->findRecords('name ASC',-1, $where);

answered Feb 26 '11 at 2:44

Masino Sinaga

41

add comment
enter at least 15 characters
0

You mean like this?: $categories->findRecords('name ASC' $where = "category != 'basic-recipes' ";);

I tried that but got an syntax error.

answered Feb 16 '11 at 6:28

databell

56

Assuming basic-recipes is the category slug, then you should do category.slug != 'basic-recipes' – hsatterwhite Feb 16 '11 at 7:56
add comment
enter at least 15 characters
0

ah sorry forgot the dot traversal. my example was for this if your wondering:

$where = "category.slug != 'basic-recipes' "; $categories->findRecords('name ASC',-1, $where);

answered Feb 17 '11 at 12:10

Rhys L. Bartels-Waller

35

add comment
enter at least 15 characters
0

Interesting. I now get a SQL Error as follows:

SQL failed; SQL: SELECT SQL_CALC_FOUND_ROWS DISTINCT t.*, p.id AS pod_id, p.created, p.modified FROM wp_pod p INNER JOIN wp\_pod\_tbl\_recipe\_category t ON t.id = p.tbl_row_id WHERE p.datatype = 4 AND ( category.slug != 'basic-recipes' ) ORDER BY name ASC; Response: Unknown column 'category.slug' in 'where clause'

answered Feb 17 '11 at 7:21

databell

56

Sorry, trying wrapping basic-recipes in double quotes instead of single quotes. Also ensure that slug is the machine name of your slug field in the category pod. – hsatterwhite Feb 17 '11 at 9:31
add comment
enter at least 15 characters
0

Yes, slug is the machine name. However, trying to place basic-recipes in double quotes like this:

$where = "category.slug != "basic-recipes" "; $categories->findRecords('name ASC',-1, $where);

Created a fatal error like this: Parse error: syntax error, unexpected T_STRING in /home/thissite/public_html/wp-content/themes/tgsplit/categories.php on line 28

and going like this:

$where = "category.slug != ''basic-recipes'' "; $categories->findRecords('name ASC',-1, $where);

Brought up this: SQL failed; SQL: SELECT SQL_CALC_FOUND_ROWS DISTINCT t.*, p.id AS pod_id, p.created, p.modified FROM wp_pod p INNER JOIN wp\_pod\_tbl\_recipe\_category t ON t.id = p.tbl_row_id WHERE p.datatype = 4 AND ( category.slug != ''basic-recipes'' ) ORDER BY name ASC; Response: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'basic-recipes'' ) ORDER BY name ASC' at line 11

answered Feb 20 '11 at 8:18

databell

56

add comment
enter at least 15 characters
0

Try this:

$where = ' category.slug != " basic-recipes " '; $categories->findRecords('name ASC',-1, $where);

answered Feb 20 '11 at 9:45

Rhys L. Bartels-Waller

35

add comment
enter at least 15 characters
0

I'm still getting the SQL error:

SQL failed; SQL: SELECT SQL_CALC_FOUND_ROWS DISTINCT t.*, p.id AS pod_id, p.created, p.modified FROM wp_pod p INNER JOIN `wp_pod_tbl_recipe_category` t ON t.id = p.tbl_row_id WHERE p.datatype = 4 AND ( category.slug != ''basic-recipes'' ) ORDER BY name ASC; Response: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'basic-recipes'' ) ORDER BY name ASC' at line 11

Just to review, here's how I have my code laid out:

<?php
                $recipes = new Pod('recipe');
        $category = pods_url_variable(-1);
                $where = ' category.slug != " basic-recipes " '; $categories->findRecords('name ASC',-1, $where);
                $total_cats = $recipes->getTotalRows();
                ?>

answered Feb 26 '11 at 1:32

databell

56

add comment
enter at least 15 characters
0

Yea, I think that finally worked. Thank you, Masino!

answered Feb 27 '11 at 6:56

databell

56

add comment
enter at least 15 characters