I am looking for a way to filter my content to only show the last posted content type. I would also like the ability to use a content:author relationship so there would only be one of each content type per user.

Possible?

Comments

cfox612’s picture

I need the same sort of functionality. I don't see this being able to happen with one view, but you could make multiple block views (one for each content type) and manipulate that way.

ravi.kumar88’s picture

This can be implemented using the views_php module.
Please follow the steps:
1.Download and install views_php module
2.Create a view with all the fields required related to the content like content type,content,author id etc.
3.Add a new filter criteria as Global:PHP and under the filter code write the following code :

  $latestPost=db_query( "SELECT MAX(node.created) FROM {node} where type ='$data->node_type' and uid = '$row->uid'")->fetchColumn();
  if ($latestPost == $data->node_created)
      return FALSE;
  else
      return TRUE;
esmerel’s picture

There's also the representative node... relationship? I think. I can't remember how to get to it, but that may help you along.

esmerel’s picture

Status: Active » Fixed
eminencehealthcare’s picture

Thank you Ravi.
I am getting an error with test_drp.node, do I have to rename that to something else?
I tried renaming to my_content_type_machine_name.node and still no dice.

I will also try your suggestion Esmerel, thanks.

eminencehealthcare’s picture

The error I receive Ravi is this:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test_drp.node' doesn't exist

What should I replace test_drp.node with?

vensires’s picture

When using db_query(), instead of FROM test_drp.node write FROM {node}. It's up to Drupal to define the database name and possible table name prefix.

eminencehealthcare’s picture

Thanks for the reply vensires, that got rid of the error.
However the code still does not seem to be working correctly.

I have a table view of content fields.
My fields are:
Content:Title
Content:User Name

I have two filters:
Content:Type (=My content type)
Global:PHP (The PHP filter)

My results are still showing more than one content type row per user.

eminencehealthcare’s picture

Status: Fixed » Active
vensires’s picture

Are you sure you have to write PHP to accomplish this?
Have you tried sorting the results (thanks to the Sort section of Views) and then Grouping them By Content Type (by enabling Aggregation in Advanced section of View) ?

ravi.kumar88’s picture

StatusFileSize
new8.3 KB
new64.97 KB
new41.6 KB

Hi,
The procedure is working fine for me.Please check the screenshots.
And thanks vensires for 'test_drp.node'.I have improved the code.
Also I am unable to find a way out using Aggregation as we have to filter out the contents on the basis of both the content type and its author.
I would appreciate if you give detailed step to implement it.

eminencehealthcare’s picture

StatusFileSize
new19.68 KB
new28.79 KB

Thank you guys for your persistent help.
Here are screen shots of what my view looks like and the results I am getting:

In my results it is still showing multiple content of the same content type per author.

Vensires, I agree with Ravi on the sort/aggregation method I cant find a way to do it because we have to filter out the contents on the basis of both the content type and its author. If you still think this is a good option would would the sort criteria/aggregation settings be?

ravi.kumar88’s picture

Hi,
I went through the screenshots you provided.I think you are missing the sort criteria in the view.
Could you please add a Content:Post date (desc) sort criteria to the same view and check again?

eminencehealthcare’s picture

Thanks I was missing the sort criteria.

I figured out what the main problem was.
I was using field: User name instead of Field: UID
In the code it is set to UID. FACEPALM!!

One more thing I notice though, I cannot sort by anything or it breaks and no results show.

Thank you so much for your help.

ravi.kumar88’s picture

Notice: Undefined property: stdClass::$node_created in __lambda_func() (line 2 of /sites/all/modules/views_php/plugins/views/views_php_handler_filter.inc(82) : runtime-created function).

This is the error coming when you use any other sort criteria other than content:post date.
I think that is coming due to the conflict in the queries given in the Global:PHP in filter section.
Also if you have to show the latest post you need to have that sort criteria.

eminencehealthcare’s picture

I am fine just using post date sort criteria. I am trying to table sort and default column sorting in the settings section. I do not receive an error but no results show when using any configuration of that sort method.

eminencehealthcare’s picture

Issue summary: View changes

:)

mustanggb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)