How to display non featured wordpress posts - wordpress

I have upload a plugin as 'featured posts' to add featured posts, also adding regular posts, both type of posts having default category(say, buy know). I want to display only regular posts(i.e non featured), but I unable to display only the regular posts, its displaying total posts(i.e regular plus featured). Please any one help me to display only the regular posts.
Thanks
Shama

$feature_ids=array();
$query=query_posts('featured'=>'yes');
while(have_posts()):the_post();
$feature_ids[]=get_the_ID();
endwhile;wp_reset_query();
// now your feature posts id store in $feature_ids as array then
// in actual query
$query=new WP_Query('post__not_in'=>$feature_ids);
// it will exclude the posts that are feature
if(have_posts()):while(have_posts()):the_post();
// yours data
endwhile;endif;wp_reset_query();

Related

I need to change a wp plugin to choose another taxonomy according to the page that i use it

I am using the post-grid-and-filter-ultimate plugin to create some filters.
I am also using a plugin to create custom taxonomies.
I have created 5 different blog pages where i need to display different filters
1st page is using the taxonomy vegan which have filters burger, pizza etc
2nd page is using taxonomy vegetarian which have filters burger, pizza etc
and so on.
I would like the plugin to read different taxonomy for every page.
This one here
if( !defined( 'PGAFU_CAT' ) ) {
define( 'PGAFU_CAT', 'vegan_dish' );
}
defines the category/taxonomy.
For blogpage with title "vegan places" it should read the taxonomy "vegan_dish". For blog page with title "vegetarian places" it skould read the taxonomy "vegetarian_dish" and so on.
I believe that this could be done with a "for" but dont know how to let it read the page titles/ids of wordpress
Any ideas?
Thanks in advance

WordPress: display full post AND excerpts on one page

Is there a way my category archive display both full posts and excerpts?
What I want is the first two or three latest posts display as full content posts, and all the others as excerpts with just title and a read more button. These are displayed on one page. I am currently using a category archive, on the twentyfifteen theme.
I know I can set a page to either display full or just excerpts, but not a combination. Is this possible?
Thanks!
You can get these in your wordpress loop on page or post.
<?php
$content = get_content($post->ID); //full content of post
$excerpt = substr($content,0,150); //you can limit charaacter like 150
?>

Dropdown of existing posts in a metabox

I want to have ability to choose for each page what post should appear in a sidebar, from multiple posts type. So I understand that I need a meta box with a dropdown list of all posts, but I don't know how to build this in functions.
I only found this solution which is quite similar to what I want, but this doesn't help me to much, because I can only choose from a single post type and display only in post pages.
There is a free plugin that will solve all of your woes. It's called ACF or Advanced Custom Fields. It has the ability to add a list of posts to a field and attach that field to pages. Here's how you'd do it:
First install the plugin and navigate to the custom fields screen. Setup your field exactly like this:
Then in the options below that section you need to select these options:
That will tell ACF to put the field only on pages. After you have set that up you will get a little sidebar block like this:
You can then select each post for the page and it will return that object on the frontend. You do need to use a little code to get the frontend to spit out the posts you need. Here is the code to get a frontend option from ACF. Inside of the sidebar.php file you need to add this code:
global $post; // Get the global post object
$sidebar_posts = get_field('posts', $post->ID); // Get the field using the post ID
foreach($sidebar_posts as $sidebar_post){ // Loop through posts
echo $sidebar_post->post_title; // Echo the post title
}
This will simply loop through the posts you select and echo out the title. You can do more with this by adding some other Wordpress post functions using setup_postdata(). This will allow you to do things like the_title() and the_content().
Hope this helps!

Custom WP_Query not working (listing featured articles + popular articles)

I am Wordpress beginer and I want to set multiple queries on a page that lists my posts.
Featured posts
I have front page that lists featured posts from all categories,
Categories pages that lists featured posts from current category
Q: Is it better to use My featured posts new category name or to set sticky post (under public - publish options) for posts I want to feature on front page and on categories pages? Every post already have his own category like News so the My featured posts will be the second category.
Query
Let's suppose I'm using category name for featured posts (but then i got permalink to My featured posts category (site/my-featured-posts/2013/07.....) which I don't want (so maybe sticky posts are better solution)
I'm trying to setup query to list featured posts but only from standard post type, not gallery or video
<?php
$arg = array(
'cattegory_name' => 'my-featured-category',
'posts_per_page' => 5,
'nopaging' => true,
'post_status' => 'publish',
'post_type' => 'post'
);
$featured= new WP_Query($arg);
if ($featured->have_posts()):
while ($featured->have_posts()) :
$featured->the_post();
?>
and then below the_title(); ..... and so on
What I get is all articles from all categories.
Q: Also, how to I get popular articles based on views and number of comments for the last day?
Q: How to list posts which have post format video?
Q: Are there any online tools that build wp_query based on criteria?
Thank you.
You can also set posts as "featured" using a tag. You can then use tag=featured with WP_Query to get posts tagged with a certain tag ("featured" in this example).
As for your additional questions...
Q1: You can save page views to a flat file or to the WordPress database. Once I used the database to store a UNIX-timestamp as traditional WP post meta for each post page view. As it was a timestamp, I could calculate the age of the page view easily (and I could also run SQL queries to remove post meta that was older than a certain timespan).
Comments can be queried by time ordering too. See WP_Comment_Query.
Of course there are plugins that can do this for you, but for me they included useless bloat I did not need.
Q2: For querying post formats, use the query variable called tax_query as GATEKeeper did in a WP support question: http://wordpress.org/support/topic/post-formats#post-2034414.
Q3: A google query returned a thing called The WordPress Query Generator.

wordpress 3.1+ - custom post types - single template - next and previous navigation links

I'm using wordpress 3.1
I got 3 types of custom types : videos, galleries and podcasts. They use the default taxonomy categories.
When viewing a single custom post let's say a video, the next_post_link() (or previous_post_link) function works as planed but it links only to the next or previous post from this custom post type.
How could I get it to display the next post from any post type? tried to search hours on google without finding anything relevant to this. Anyone facing the same issue?
You'll need to remove the post_type clause from the SQL query used to retrieve the adjacent post. This can be done by hooking into the get_next_post_where and get_previous_post_where filters, although it's not ideal as the SQL query is passed as a single string.
add_filter('get_next_post_where', 'my_get_adjacent_post_where_filter');
add_filter('get_previous_post_where', 'my_get_adjacent_post_where_filter');
function my_get_adjacent_post_where_filter($sql) {
return preg_replace("/ AND p.post_type = '[^']*'/", '', $sql);
}

Resources