I'm creating a new module with apostrophe cms, How would I populate a select field type with all of the blog posts from apostrophe-blogs - blogs

I had thought about trying to use a join, but not sure how to connect a select field to populate with all the latest blog postings.

Instead of using a select field to access blog posts from a schema, I would recommend using a join field pointed at your blog piece type.
Getting started with joins can be found in the documentation here
http://apostrophecms.org/docs/tutorials/getting-started/schema-guide.html#code-join-by-one-code
You can join to a single piece or an array of pieces by usingjoinByOne and joinByArray, respectively.

Related

Create Multi-Object JSON Arrays in MySQL

As the image suggests I need to find a way to put the values from another table with same ID into an JSON object consists of JSON-array.
This is the article click for the link I am seeing and it's in SQL Server I need to use it in MySQL.
Any help will be appreciated.
For now, I am just doing inner join within two tables.
But not getting result as expected.

SQL to Django Translation

This statement works in SQL, I just cannot figure out how to convert it to django. Im sure it uses prefetch_related, Prefetch, or select_related but im still having a hard time understanding those concepts. I do see that prefetch basically has to have the field under that table.
My goal: Not all brands have products. All products have brands. Show my only brands with products. I was hoping to implement Brand.objects.[insert-filter-here]
Model.py (appended version of actual models.py file)
class Product(models.Model):
brand = models.ForeignKey(Brand)
class Brand(models.Model):
name = models.CharField
SQL
SELECT DISTINCT products_brand.name FROM produts_brand INNER JOIN products_product on products_brand.id=products_product.brand_id;
Its 2 tables becuase the products table has many many columns (27), I guess the other option is to just
combine them. But I wanted more control over Brand objects for ease of lookup/editing.
Many thanks for your help!
It should just be Brand.objects.filter(product__isnull=False).distinct(). You can follow the foreign key relation backwards using the default reverse name (or a different one if you used the related_query_name field argument to specify one when declaring your ForeignKeyField).
Without the distinct() you may get duplicate entries.
See the "Lookups that span relationships" docs for more details and examples.
Thanks guys! I failed to mention i was using MYSQL backend and not SQLite but Peters answer got me in the right direction though, I got.
Brand.objects.values('name').distinct().filter(products__isnull=False)

Batch add tags to posts via phpmyadmin - wordpress

How would I go about batch assigning tags to posts via phpmyadmin? I have a custom table in my database that contains the postID and one column with a comma separated list of keywords for each post/record. I want to use the keyword column as values for my tags for each post.
Is there any way for me to get those tags over to the wp_term_relationships table using an sql query?
Right now I already have each post assigned to one category (and some posts assigned to two categories)...if that makes any difference....I am dealing with almost 200,000 posts.
Thanks for the help!!
I thought I could do this with sql queries but that is just over my head..so I did some extensive searching for plugins (free plugins that is...).
I came up with this, which is working....
Installed the 'WP Post Corrector' plugin, it is old and not updated anymore but it is working with my 3.5.1 wordpress. I have a massive csv file with 2 columns (ID -> which is the same as my wp post ID, and post_tag -> which is a list of comma separated tags). I split the file up into smaller chuncks so php or the server wouldn't crap out (http://sourceforge.net/projects/splitcsv/) - I made each file have 5000 records.
Yes, it took me about an hour to upload about 40 files, but now it is done.

MySQL exporting WordPress posts with related meta data

I'm using the WP-Property plugin for an estate agents site. They want to use RightMove to display their properties as well, so I'm looking for a way to export the post type 'property' with all its related meta data.
Most of the data for a property is in the posts table, but things like the number of bedrooms, price etc are in the post meta table.
I'm not much of a back end coder, so I think I need an SQL query that will join the two tables together?
I have to convert it to a BLM file for RightMove, but I'm taking it one stage at a time, so getting the data I need out is what I need to do.
Is anyone able to point me in the right direction?
Thanks
Yes you need to write a join where the post_id of postmeta table is equal to the id of posts table

WordPressMU - get blog list, alphabetically sorted by blogname

In WordPress MU, I've tried writing my own query for this but can't seem to get all of the joins I really need. The result set I'm looking for would be something like:
blog_id
blog name
blog path
owner first name
owner last name
and return it all alphabetically, by blog name. The trouble I'm having is that the first and last name of the blog owner are in wp_usermeta, the blog id and path are in wp_blogs, and the blog name is in wp_[blog id here]_options, with wp_usermeta requiring the user ID from wp_users.
Is it possible to join all of this in one query?
There is not a way to combine all of the information into one result set because of the way WPMU handles the database table names.
The best solution I have come up with is some PHP logic that gets the blogs from the wp_blogs table, uses the IDs there to gather information from the wp_X_options tables, and then builds up the information I need. It's the same reason there is no good way to get a list of all the posts across all of the blogs with just a query. You need backend logic to build the query based on the blogs in wp_blogs.