asked on
class pc_npPosts
{
function pc_get_np_info(){
$pc_np_author_id = get_query_var( 'author' );
$pc_np_name = get_field('np_organization_name', 'user_'. $pc_np_author_id);
$pc_np_bio = apply_filters('avf_author_description', get_the_author_meta('description', $pc_np_author_id), $pc_np_author_id);
$pc_np_whatWeDo = get_field('np_what_we_do', 'user_'. $pc_np_author_id);
$np_organization_logo = get_field( 'np_organization_logo', 'user_'. $pc_np_author_id );
$np_profile_link = get_author_posts_url($pc_np_author_id);
$np_organization_address = get_field( 'np_organization_address', 'user_'. $pc_np_author_id );
$np_organization_city = get_field( 'np_organization_city', 'user_'. $pc_np_author_id );
$np_organization_state = get_field( 'np_organization_state', 'user_'. $pc_np_author_id );
$np_organization_zipcode = get_field( 'np_organization_zipcode', 'user_'. $pc_np_author_id );
$np_causes_interests = get_field( 'np_causes_interests', 'user_'. $pc_np_author_id );
}
}
$pc_np_author = New pc_npPosts;
echo $pc_np_class->pc_get_np_info('pc_np_name');
ASKER
class pc_npPosts
{
$pc_np_author_id = get_query_var( 'author' );
$pc_np_name = get_field('np_organization_name', 'user_'. $pc_np_author_id);
$pc_np_bio = apply_filters('avf_author_description', get_the_author_meta('description', $pc_np_author_id), $pc_np_author_id);
$pc_np_whatWeDo = get_field('np_what_we_do', 'user_'. $pc_np_author_id);
$np_organization_logo = get_field( 'np_organization_logo', 'user_'. $pc_np_author_id );
$np_profile_link = get_author_posts_url($pc_np_author_id);
$np_organization_address = get_field( 'np_organization_address', 'user_'. $pc_np_author_id );
$np_organization_city = get_field( 'np_organization_city', 'user_'. $pc_np_author_id );
$np_organization_state = get_field( 'np_organization_state', 'user_'. $pc_np_author_id );
$np_organization_zipcode = get_field( 'np_organization_zipcode', 'user_'. $pc_np_author_id );
$np_causes_interests = get_field( 'np_causes_interests', 'user_'. $pc_np_author_id );
}
Now they're accessible as properties so you can echo them out:$posts = new pc_npPosts();
echo $posts->pc_np_author_id;
echo $posts->$np_organization_logo;
Depending on your needs, there's probably a much more efficient way of doing this. As it stands, everytime you instantiate the class, you're call all those get_field() methods, whether you need them or not.
ASKER
ASKER
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY